mirror of https://github.com/naudio/NAudio.git

23 changed files with 467 additions and 0 deletions
-
4NAudio/Changes.xml
-
13NAudio/Dmo/DmoEnumFlags.cs
-
46NAudio/Dmo/DmoEnumerator.cs
-
21NAudio/Dmo/DmoGuids.cs
-
15NAudio/Dmo/DmoInputDataBufferFlags.cs
-
13NAudio/Dmo/DmoInputStatusFlags.cs
-
21NAudio/Dmo/DmoInterop.cs
-
24NAudio/Dmo/DmoMediaType.cs
-
14NAudio/Dmo/DmoOutputDataBuffer.cs
-
16NAudio/Dmo/DmoOutputDataBufferFlags.cs
-
15NAudio/Dmo/DmoPartialMediaType.cs
-
13NAudio/Dmo/DmoProcessOutputFlags.cs
-
14NAudio/Dmo/DmoSetTypeFlags.cs
-
22NAudio/Dmo/IEnumDmo.cs
-
18NAudio/Dmo/IMediaBuffer.cs
-
59NAudio/Dmo/IMediaObject.cs
-
23NAudio/Dmo/IWMResamplerProps.cs
-
16NAudio/Dmo/InputStreamInfoFlags.cs
-
16NAudio/Dmo/OutputStreamInfoFlags.cs
-
21NAudio/Dmo/ResamplerMediaObject.cs
-
19NAudio/NAudio.csproj
-
43NAudioTests/DmoTests.cs
-
1NAudioTests/NAudioTests.csproj
@ -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 |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
|||
} |
@ -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"); |
|||
} |
|||
} |
@ -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 |
|||
} |
|||
} |
@ -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 |
|||
} |
|||
} |
@ -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); |
|||
|
|||
} |
|||
} |
@ -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;
|
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
@ -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 |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
@ -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 |
|||
} |
|||
} |
@ -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 |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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 |
|||
} |
|||
} |
@ -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 |
|||
} |
|||
} |
@ -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 |
|||
{ |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue