■ MediaFoundationApi 클래스의 EnumerateTransforms 정적 메소드를 사용해 미디어 파운데이션 변환을 열거하는 방법을 보여준다.
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using NAudio.CoreAudioApi.Interfaces; using NAudio.MediaFoundation; using NAudio.Utils; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 어트리뷰트 추가하기 - AddAttribute(stringBuilder, mfActivate, index) /// <summary> /// 어트리뷰트 추가하기 /// </summary> /// <param name="stringBuilder">문자열 빌더</param> /// <param name="mfActivate">MF 활성자</param> /// <param name="index">인덱스</param> private static void AddAttribute(StringBuilder stringBuilder, IMFActivate mfActivate, int index) { IntPtr propertyVariantHandle = Marshal.AllocHGlobal(Marshal.SizeOf<PropVariant>()); try { mfActivate.GetItemByIndex(index, out var key, propertyVariantHandle); PropVariant propertyVariant = (PropVariant)Marshal.PtrToStructure(propertyVariantHandle, typeof(PropVariant)); string propertyName = FieldDescriptionHelper.Describe(typeof (MediaFoundationAttributes), key); if(key == MediaFoundationAttributes.MFT_INPUT_TYPES_Attributes || key == MediaFoundationAttributes.MFT_OUTPUT_TYPES_Attributes) { MFT_REGISTER_TYPE_INFO[] typeInformationArray = propertyVariant.GetBlobAsArrayOf<MFT_REGISTER_TYPE_INFO>(); stringBuilder.AppendFormat("{0} : {1} 항목", propertyName, typeInformationArray.Length); stringBuilder.AppendLine(); foreach(MFT_REGISTER_TYPE_INFO typeInformation in typeInformationArray) { stringBuilder.AppendFormat ( " {0}-{1}", FieldDescriptionHelper.Describe(typeof (MediaTypes ), typeInformation.guidMajorType), FieldDescriptionHelper.Describe(typeof (AudioSubtypes), typeInformation.guidSubtype ) ); stringBuilder.AppendLine(); } } else if(key == MediaFoundationAttributes.MF_TRANSFORM_CATEGORY_Attribute) { stringBuilder.AppendFormat ( "{0} : {1}", propertyName, FieldDescriptionHelper.Describe(typeof (MediaFoundationTransformCategories), (Guid) propertyVariant.Value) ); stringBuilder.AppendLine(); } else if(propertyVariant.DataType == (VarEnum.VT_VECTOR | VarEnum.VT_UI1)) { byte[] valueArray = (byte[]) propertyVariant.Value; stringBuilder.AppendFormat("{0} : BLOB {1} 바이트", propertyName, valueArray.Length); stringBuilder.AppendLine(); } else { stringBuilder.AppendFormat("{0} : {1}", propertyName, propertyVariant.Value); stringBuilder.AppendLine(); } } finally { PropVariant.Clear(propertyVariantHandle); Marshal.FreeHGlobal(propertyVariantHandle); } } #endregion #region 설명하기 - Describe(mfActivate) /// <summary> /// 설명하기 /// </summary> /// <param name="mfActivate">MF 활성자</param> /// <returns>설명</returns> private static string Describe(IMFActivate mfActivate) { mfActivate.GetCount(out var attributeCount); StringBuilder stringBuilder = new StringBuilder(); for(int i = 0; i < attributeCount; i++) { AddAttribute(stringBuilder, mfActivate, i); } return stringBuilder.ToString(); } #endregion #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { Console.WriteLine("--------------------------------------------------"); Console.WriteLine("오디오 이펙트"); Console.WriteLine("--------------------------------------------------"); IEnumerable<IMFActivate> audioEffectEnumerable = MediaFoundationApi.EnumerateTransforms ( MediaFoundationTransformCategories.AudioEffect ); foreach(IMFActivate mfActivate in audioEffectEnumerable) { Console.WriteLine(Describe(mfActivate)); Console.WriteLine(); } Console.WriteLine("--------------------------------------------------"); Console.WriteLine("오디오 디코더"); Console.WriteLine("--------------------------------------------------"); IEnumerable<IMFActivate> audioDecoderEnumerable = MediaFoundationApi.EnumerateTransforms ( MediaFoundationTransformCategories.AudioDecoder ); foreach(IMFActivate mfActivate in audioDecoderEnumerable) { Console.WriteLine(Describe(mfActivate)); Console.WriteLine(); } Console.WriteLine("--------------------------------------------------"); Console.WriteLine("오디오 인코더"); Console.WriteLine("--------------------------------------------------"); IEnumerable<IMFActivate> audioEncoderEnumerable = MediaFoundationApi.EnumerateTransforms ( MediaFoundationTransformCategories.AudioEncoder ); foreach(IMFActivate mfActivate in audioEncoderEnumerable) { Console.WriteLine(Describe(mfActivate)); Console.WriteLine(); } } #endregion } } |