using System;
using System.Runtime.InteropServices;
using NAudio.CoreAudioApi.Interfaces;
namespace NAudio.Dmo
{
///
/// 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
///
[ComImport, Guid("f447b69e-1884-4a7e-8055-346f74d6edb3")]
class ResamplerMediaComObject
{
}
///
/// DMO Resampler
///
public class DmoResampler : IDisposable
{
MediaObject mediaObject;
IPropertyStore propertyStoreInterface;
IWMResamplerProps resamplerPropsInterface;
ResamplerMediaComObject mediaComObject;
///
/// Creates a new Resampler based on the DMO Resampler
///
public DmoResampler()
{
mediaComObject = new ResamplerMediaComObject();
mediaObject = new MediaObject((IMediaObject)mediaComObject);
propertyStoreInterface = (IPropertyStore)mediaComObject;
resamplerPropsInterface = (IWMResamplerProps)mediaComObject;
}
///
/// Media Object
///
public MediaObject MediaObject => mediaObject;
#region IDisposable Members
///
/// Dispose code - experimental at the moment
/// Was added trying to track down why Resampler crashes NUnit
/// This code not currently being called by ResamplerDmoStream
///
public void Dispose()
{
if(propertyStoreInterface != null)
{
Marshal.ReleaseComObject(propertyStoreInterface);
propertyStoreInterface = null;
}
if(resamplerPropsInterface != null)
{
Marshal.ReleaseComObject(resamplerPropsInterface);
resamplerPropsInterface = null;
}
if (mediaObject != null)
{
mediaObject.Dispose();
mediaObject = null;
}
if (mediaComObject != null)
{
Marshal.ReleaseComObject(mediaComObject);
mediaComObject = null;
}
}
#endregion
}
}