Browse Source

loads of DMO (DirectX Media Objects) interop. Can enumerate DMOs

pull/1/head
markheath 17 years ago
parent
commit
d42bd02eac
  1. 4
      NAudio/Changes.xml
  2. 13
      NAudio/Dmo/DmoEnumFlags.cs
  3. 46
      NAudio/Dmo/DmoEnumerator.cs
  4. 21
      NAudio/Dmo/DmoGuids.cs
  5. 15
      NAudio/Dmo/DmoInputDataBufferFlags.cs
  6. 13
      NAudio/Dmo/DmoInputStatusFlags.cs
  7. 21
      NAudio/Dmo/DmoInterop.cs
  8. 24
      NAudio/Dmo/DmoMediaType.cs
  9. 14
      NAudio/Dmo/DmoOutputDataBuffer.cs
  10. 16
      NAudio/Dmo/DmoOutputDataBufferFlags.cs
  11. 15
      NAudio/Dmo/DmoPartialMediaType.cs
  12. 13
      NAudio/Dmo/DmoProcessOutputFlags.cs
  13. 14
      NAudio/Dmo/DmoSetTypeFlags.cs
  14. 22
      NAudio/Dmo/IEnumDmo.cs
  15. 18
      NAudio/Dmo/IMediaBuffer.cs
  16. 59
      NAudio/Dmo/IMediaObject.cs
  17. 23
      NAudio/Dmo/IWMResamplerProps.cs
  18. 16
      NAudio/Dmo/InputStreamInfoFlags.cs
  19. 16
      NAudio/Dmo/OutputStreamInfoFlags.cs
  20. 21
      NAudio/Dmo/ResamplerMediaObject.cs
  21. 19
      NAudio/NAudio.csproj
  22. 43
      NAudioTests/DmoTests.cs
  23. 1
      NAudioTests/NAudioTests.csproj

4
NAudio/Changes.xml

@ -774,4 +774,8 @@
<version>31 May 2008</version>
<version>WASAPI out working! but need a solution for SRC</version>
</change>
<change>
<version>1.2.127.0</version>
<version>Lots of DMO interop written (DirectX media objects)</version>
</change>
</changes>

13
NAudio/Dmo/DmoEnumFlags.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum DmoEnumFlags
{
None,
DMO_ENUMF_INCLUDE_KEYED = 0x00000001
}
}

46
NAudio/Dmo/DmoEnumerator.cs

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
public class DmoEnumerator
{
public static IEnumerable<string> GetAudioEffectNames()
{
return GetNames(DmoGuids.DMOCATEGORY_AUDIO_EFFECT);
}
public static IEnumerable<string> GetAudioEncoderNames()
{
return GetNames(DmoGuids.DMOCATEGORY_AUDIO_ENCODER);
}
public static IEnumerable<string> GetAudioDecoderNames()
{
return GetNames(DmoGuids.DMOCATEGORY_AUDIO_DECODER);
}
private static IEnumerable<string> GetNames(Guid category)
{
IEnumDmo enumDmo;
int hresult = DmoInterop.DMOEnum(ref category, DmoEnumFlags.None, 0, null, 0, null, out enumDmo);
Marshal.ThrowExceptionForHR(hresult);
Guid guid;
int itemsFetched;
IntPtr namePointer;
do
{
enumDmo.Next(1, out guid, out namePointer, out itemsFetched);
if (itemsFetched == 1)
{
string name = Marshal.PtrToStringUni(namePointer);
Marshal.FreeCoTaskMem(namePointer);
yield return name;
}
} while (itemsFetched > 0);
}
}
}

21
NAudio/Dmo/DmoGuids.cs

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
/// <summary>
/// DMO Guids for use with DMOEnum
/// dmoreg.h
/// </summary>
static class DmoGuids
{
public static readonly Guid DMOCATEGORY_AUDIO_DECODER = new Guid("57f2db8b-e6bb-4513-9d43-dcd2a6593125");
public static readonly Guid DMOCATEGORY_AUDIO_ENCODER = new Guid("33D9A761-90C8-11d0-BD43-00A0C911CE86");
public static readonly Guid DMOCATEGORY_VIDEO_DECODER = new Guid("4a69b442-28be-4991-969c-b500adf5d8a8");
public static readonly Guid DMOCATEGORY_VIDEO_ENCODER = new Guid("33D9A760-90C8-11d0-BD43-00A0C911CE86");
public static readonly Guid DMOCATEGORY_AUDIO_EFFECT = new Guid("f3602b3f-0592-48df-a4cd-674721e7ebeb");
public static readonly Guid DMOCATEGORY_VIDEO_EFFECT = new Guid("d990ee14-776c-4723-be46-3da2f56f10b9");
public static readonly Guid DMOCATEGORY_AUDIO_CAPTURE_EFFECT = new Guid("f665aaba-3e09-4920-aa5f-219811148f09");
}
}

15
NAudio/Dmo/DmoInputDataBufferFlags.cs

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum DmoInputDataBufferFlags
{
None,
DMO_INPUT_DATA_BUFFERF_SYNCPOINT = 0x00000001,
DMO_INPUT_DATA_BUFFERF_TIME = 0x00000002,
DMO_INPUT_DATA_BUFFERF_TIMELENGTH = 0x00000004
}
}

13
NAudio/Dmo/DmoInputStatusFlags.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum DmoInputStatusFlags
{
None,
DMO_INPUT_STATUSF_ACCEPT_DATA = 0x1
}
}

21
NAudio/Dmo/DmoInterop.cs

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
static class DmoInterop
{
[DllImport("msdmo.dll")]
public static extern int DMOEnum(
[In] ref Guid guidCategory,
DmoEnumFlags flags,
int inTypes,
[In] DmoPartialMediaType[] inTypesArray,
int outTypes,
[In] DmoPartialMediaType[] outTypesArray,
out IEnumDmo enumDmo);
}
}

24
NAudio/Dmo/DmoMediaType.cs

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
/// <summary>
/// http://msdn.microsoft.com/en-us/library/aa929922.aspx
/// DMO_MEDIA_TYPE
/// </summary>
struct DmoMediaType
{
Guid majortype;
Guid subtype;
bool bFixedSizeSamples;
bool bTemporalCompression;
int lSampleSize;
Guid formattype;
IntPtr pUnk;
int cbFormat;
IntPtr pbFormat; // not used
//[size_is(cbFormat)] BYTE* pbFormat;
}
}

14
NAudio/Dmo/DmoOutputDataBuffer.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
struct DmoOutputDataBuffer
{
IMediaBuffer pBuffer;
DmoOutputDataBufferFlags dwStatus;
long rtTimestamp;
long referenceTimeDuration;
}
}

16
NAudio/Dmo/DmoOutputDataBufferFlags.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum DmoOutputDataBufferFlags
{
None,
DMO_OUTPUT_DATA_BUFFERF_SYNCPOINT = 0x00000001,
DMO_OUTPUT_DATA_BUFFERF_TIME = 0x00000002,
DMO_OUTPUT_DATA_BUFFERF_TIMELENGTH = 0x00000004,
DMO_OUTPUT_DATA_BUFFERF_INCOMPLETE = 0x01000000
}
}

15
NAudio/Dmo/DmoPartialMediaType.cs

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
/// <summary>
/// DMO_PARTIAL_MEDIATYPE
/// </summary>
struct DmoPartialMediaType
{
Guid type;
Guid subtype;
}
}

13
NAudio/Dmo/DmoProcessOutputFlags.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum DmoProcessOutputFlags
{
None,
DMO_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER = 0x00000001
}
}

14
NAudio/Dmo/DmoSetTypeFlags.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum DmoSetTypeFlags
{
None,
DMO_SET_TYPEF_TEST_ONLY = 0x00000001,
DMO_SET_TYPEF_CLEAR = 0x00000002
}
}

22
NAudio/Dmo/IEnumDmo.cs

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
[Guid("2c3cd98a-2bfa-4a53-9c27-5249ba64ba0f"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IEnumDmo
{
// int Next(int itemsToFetch, CLSID[] clsids, string[] names, out int itemsFetched);
// lets do one at a time to keep it simple - don't call with itemsToFetch > 1
int Next(int itemsToFetch, out Guid clsid, out IntPtr name, out int itemsFetched);
int Skip(int itemsToSkip);
int Reset();
int Clone(out IEnumDmo enumPointer);
}
}

18
NAudio/Dmo/IMediaBuffer.cs

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
[Guid("59eff8b9-938c-4a26-82f2-95cb84cdc837"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IMediaBuffer
{
int SetLength(int length);
int GetMaxLength(out int maxLength);
int GetBufferAndLength(out IntPtr bufferPointer, out int validDataLength);
}
}

59
NAudio/Dmo/IMediaObject.cs

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
/// <summary>
/// defined in mediaobj.h
/// </summary>
[Guid("d8ad0f58-5494-4102-97c5-ec798e59bcf4"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IMediaObject
{
int GetStreamCount(out int inputStreams, out int outputStreams);
int GetInputStreamInfo(int inputStreamIndex, out InputStreamInfoFlags flags);
int GetOutputStreamInfo(int outputStreamIndex, out OutputStreamInfoFlags flags);
int GetInputType(int inputStreamIndex, int typeIndex, out DmoMediaType mediaType);
int GetOutputType(int outputStreamIndex, int typeIndex, out DmoMediaType mediatType);
int SetInputType(int inputStreamIndex, [In] ref DmoMediaType mediaType, DmoSetTypeFlags flags);
int SetOutputType(int outputStreamIndex, [In] ref DmoMediaType mediaType, DmoSetTypeFlags flags);
int GetInputCurrentType(int inputStreamIndex, out DmoMediaType mediaType);
int GetOutputCurrentType(int outputStreamIndex, out DmoMediaType mediaType);
int GetInputSizeInfo(int inputStreamIndex, out int size, out int maxLookahed, out int alignment);
int GetOutputSizeInfo(int outputStreamIndex, out int size, out int alignment);
int GetInputMaxLatency(int inputStreamIndex, out long referenceTimeMaxLatency);
int SetInputMaxLatency(int inputStreamIndex, long referenceTimeMaxLatency);
int Flush();
int Discontinuity(int inputStreamIndex);
int AllocateStreamingResources();
int FreeStreamingResources();
int GetInputStatus(int inputStreamIndex, out DmoInputStatusFlags flags);
int ProcessInput(int inputStreamIndex, [In] IMediaBuffer mediaBuffer, DmoInputDataBufferFlags flags,
long referenceTimeTimestamp, long referenceTimeDuration);
int ProcessOutput(DmoProcessOutputFlags flags, int outputBufferCount, DmoOutputDataBuffer[] outputBuffers,
out int statusReserved);
int Lock(bool acquireLock);
}
}

23
NAudio/Dmo/IWMResamplerProps.cs

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
/// <summary>
/// Windows Media Resampler Props
/// wmcodecdsp.h
/// </summary>
[Guid("E7E9984F-F09F-4da4-903F-6E2E0EFE56B5"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IWMResamplerProps
{
/// <summary>
/// Range is 1 to 60
/// </summary>
int SetHalfFilterLength(int outputQuality);
int SetUserChannelMtx([In] float[] channelConversionMatrix);
}
}

16
NAudio/Dmo/InputStreamInfoFlags.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum InputStreamInfoFlags
{
None,
DMO_INPUT_STREAMF_WHOLE_SAMPLES = 0x00000001,
DMO_INPUT_STREAMF_SINGLE_SAMPLE_PER_BUFFER = 0x00000002,
DMO_INPUT_STREAMF_FIXED_SAMPLE_SIZE = 0x00000004,
DMO_INPUT_STREAMF_HOLDS_BUFFERS = 0x00000008
}
}

16
NAudio/Dmo/OutputStreamInfoFlags.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Dmo
{
[Flags]
enum OutputStreamInfoFlags
{
DMO_OUTPUT_STREAMF_WHOLE_SAMPLES = 0x00000001,
DMO_OUTPUT_STREAMF_SINGLE_SAMPLE_PER_BUFFER = 0x00000002,
DMO_OUTPUT_STREAMF_FIXED_SAMPLE_SIZE = 0x00000004,
DMO_OUTPUT_STREAMF_DISCARDABLE = 0x00000008,
DMO_OUTPUT_STREAMF_OPTIONAL = 0x00000010
}
}

21
NAudio/Dmo/ResamplerMediaObject.cs

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace NAudio.Dmo
{
/// <summary>
/// From wmcodecsdp.h
/// Implements:
/// - IMediaObject
/// - IMFTransform (Media foundation - we will leave this for now as there is loads of MF stuff)
/// - IPropertyStore
/// - IWMResamplerProps
/// Can resample PCM or IEEE
/// </summary>
[ComImport, Guid("f447b69e-1884-4a7e-8055-346f74d6edb3")]
class ResamplerMediaObject
{
}
}

19
NAudio/NAudio.csproj

@ -81,6 +81,12 @@
<Compile Include="CoreAudioApi\PropertyKeys.cs" />
<Compile Include="Daw\MeasuresBeatsTicks.cs" />
<Compile Include="Daw\TempoMap.cs" />
<Compile Include="Dmo\DmoEnumerator.cs" />
<Compile Include="Dmo\DmoEnumFlags.cs" />
<Compile Include="Dmo\DmoGuids.cs" />
<Compile Include="Dmo\DmoInterop.cs" />
<Compile Include="Dmo\DmoPartialMediaType.cs" />
<Compile Include="Dmo\IWMResamplerProps.cs" />
<Compile Include="Dsp\BiQuadFilter.cs" />
<Compile Include="Dsp\Complex.cs" />
<Compile Include="Dsp\EnvelopeDetector.cs" />
@ -304,6 +310,19 @@
<Compile Include="Wave\WaveStreams\WaveOffsetStream.cs" />
<Compile Include="Wave\WaveStreams\WaveOutBuffer.cs" />
<Compile Include="Wave\WaveStreams\WaveStream.cs" />
<Compile Include="Dmo\DmoInputDataBufferFlags.cs" />
<Compile Include="Dmo\DmoInputStatusFlags.cs" />
<Compile Include="Dmo\DmoMediaType.cs" />
<Compile Include="Dmo\DmoOutputDataBuffer.cs" />
<Compile Include="Dmo\DmoOutputDataBufferFlags.cs" />
<Compile Include="Dmo\DmoProcessOutputFlags.cs" />
<Compile Include="Dmo\DmoSetTypeFlags.cs" />
<Compile Include="Dmo\IEnumDmo.cs" />
<Compile Include="Dmo\IMediaBuffer.cs" />
<Compile Include="Dmo\IMediaObject.cs" />
<Compile Include="Dmo\InputStreamInfoFlags.cs" />
<Compile Include="Dmo\OutputStreamInfoFlags.cs" />
<Compile Include="Dmo\ResamplerMediaObject.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Gui\Arranger.resx">

43
NAudioTests/DmoTests.cs

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NAudio.Dmo;
namespace NAudioTests
{
[TestFixture]
public class DmoTests
{
[Test]
public void CanEnumerateAudioEffects()
{
Console.WriteLine("Audio Effects:");
foreach (string name in DmoEnumerator.GetAudioEffectNames())
{
Console.WriteLine(name);
}
}
[Test]
public void CanEnumerateAudioEncoders()
{
Console.WriteLine("Audio Encoders:");
foreach (string name in DmoEnumerator.GetAudioEncoderNames())
{
Console.WriteLine(name);
}
}
[Test]
public void CanEnumerateAudioDecoders()
{
Console.WriteLine("Audio Decoders:");
foreach (string name in DmoEnumerator.GetAudioDecoderNames())
{
Console.WriteLine(name);
}
}
}
}

1
NAudioTests/NAudioTests.csproj

@ -52,6 +52,7 @@
<ItemGroup>
<Compile Include="AcmDriverTests.cs" />
<Compile Include="AudioClientTests.cs" />
<Compile Include="DmoTests.cs" />
<Compile Include="MidiEventCollectionTest.cs" />
<Compile Include="MMDeviceEnumeratorTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

Loading…
Cancel
Save