첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Program.cs

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요