using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
///
/// DirectX Media Object Enumerator
///
public class DmoEnumerator
{
///
/// Get audio effect names
///
/// Audio effect names
public static IEnumerable GetAudioEffectNames()
{
return GetDmos(DmoGuids.DMOCATEGORY_AUDIO_EFFECT);
}
///
/// Get audio encoder names
///
/// Audio encoder names
public static IEnumerable GetAudioEncoderNames()
{
return GetDmos(DmoGuids.DMOCATEGORY_AUDIO_ENCODER);
}
///
/// Get audio decoder names
///
/// Audio decoder names
public static IEnumerable GetAudioDecoderNames()
{
return GetDmos(DmoGuids.DMOCATEGORY_AUDIO_DECODER);
}
private static IEnumerable GetDmos(Guid category)
{
IEnumDmo enumDmo;
var hresult = DmoInterop.DMOEnum(ref category, DmoEnumFlags.None, 0, null, 0, null, out enumDmo);
Marshal.ThrowExceptionForHR(hresult);
int itemsFetched;
do
{
Guid guid;
IntPtr namePointer;
enumDmo.Next(1, out guid, out namePointer, out itemsFetched);
if (itemsFetched == 1)
{
string name = Marshal.PtrToStringUni(namePointer);
Marshal.FreeCoTaskMem(namePointer);
yield return new DmoDescriptor(name, guid);
}
} while (itemsFetched > 0);
}
}
}