/// <summary> /// Helper function to make a DMO Media Type to represent a particular WaveFormat /// </summary> private DmoMediaType CreateDmoMediaTypeForWaveFormat(WaveFormat waveFormat) { DmoMediaType mediaType = new DmoMediaType(); int waveFormatExSize = Marshal.SizeOf(waveFormat); // 18 + waveFormat.ExtraSize; DmoInterop.MoInitMediaType(ref mediaType, waveFormatExSize); mediaType.SetWaveFormat(waveFormat); return(mediaType); }
/// <summary> /// Set output type to the specified wave format /// n.b. may need to set input type first /// </summary> /// <param name="outputStreamIndex">Output stream index</param> /// <param name="waveFormat">Wave format</param> public void SetOutputWaveFormat(int outputStreamIndex, WaveFormat waveFormat) { DmoMediaType mediaType = CreateDmoMediaTypeForWaveFormat(waveFormat); bool succeeded = SetOutputType(outputStreamIndex, mediaType, DmoSetTypeFlags.None); DmoInterop.MoFreeMediaType(ref mediaType); if (!succeeded) { throw new ArgumentException("Media Type not supported"); } }
/// <summary> /// Helper method to call SetOutputType /// </summary> private bool SetOutputType(int outputStreamIndex, DmoMediaType mediaType, DmoSetTypeFlags flags) { int hresult = mediaObject.SetOutputType(outputStreamIndex, ref mediaType, flags); if (hresult == (int)DmoHResults.DMO_E_TYPE_NOT_ACCEPTED) { return(false); } else if (hresult == HResult.S_OK) { return(true); } else { throw Marshal.GetExceptionForHR(hresult); } }
/// <summary> /// Sets the input type helper method /// </summary> /// <param name="inputStreamIndex">Input stream index</param> /// <param name="mediaType">Media type</param> /// <param name="flags">Flags (can be used to test rather than set)</param> private bool SetInputType(int inputStreamIndex, DmoMediaType mediaType, DmoSetTypeFlags flags) { int hResult = mediaObject.SetInputType(inputStreamIndex, ref mediaType, flags); if (hResult != HResult.S_OK) { if (hResult == (int)DmoHResults.DMO_E_INVALIDSTREAMINDEX) { throw new ArgumentException("Invalid stream index"); } if (hResult == (int)DmoHResults.DMO_E_TYPE_NOT_ACCEPTED) { Debug.WriteLine("Media type was not accepted"); } return(false); } return(true); }
/// <summary> /// Checks if a specified output type is supported /// n.b. you may need to set the input type first /// </summary> /// <param name="outputStreamIndex">Output stream index</param> /// <param name="mediaType">Media type</param> /// <returns>True if supported</returns> public bool SupportsOutputType(int outputStreamIndex, DmoMediaType mediaType) { return(SetOutputType(outputStreamIndex, mediaType, DmoSetTypeFlags.DMO_SET_TYPEF_TEST_ONLY)); }
/// <summary> /// Helper method to call SetOutputType /// </summary> private bool SetOutputType(int outputStreamIndex, DmoMediaType mediaType, DmoSetTypeFlags flags) { int hresult = mediaObject.SetOutputType(outputStreamIndex, ref mediaType, flags); if (hresult == (int)DmoHResults.DMO_E_TYPE_NOT_ACCEPTED) { return false; } else if (hresult == HResult.S_OK) { return true; } else { throw Marshal.GetExceptionForHR(hresult); } }
/// <summary> /// Sets the output type /// n.b. may need to set the input type first /// </summary> /// <param name="outputStreamIndex">Output stream index</param> /// <param name="mediaType">Media type to set</param> public void SetOutputType(int outputStreamIndex, DmoMediaType mediaType) { if (!SetOutputType(outputStreamIndex, mediaType, DmoSetTypeFlags.None)) { throw new ArgumentException("Media Type not supported"); } }
/// <summary> /// Checks if a specified output type is supported /// n.b. you may need to set the input type first /// </summary> /// <param name="outputStreamIndex">Output stream index</param> /// <param name="mediaType">Media type</param> /// <returns>True if supported</returns> public bool SupportsOutputType(int outputStreamIndex, DmoMediaType mediaType) { return SetOutputType(outputStreamIndex, mediaType, DmoSetTypeFlags.DMO_SET_TYPEF_TEST_ONLY); }
/// <summary> /// Helper function to make a DMO Media Type to represent a particular WaveFormat /// </summary> private DmoMediaType CreateDmoMediaTypeForWaveFormat(WaveFormat waveFormat) { DmoMediaType mediaType = new DmoMediaType(); int waveFormatExSize = Marshal.SizeOf(waveFormat); // 18 + waveFormat.ExtraSize; DmoInterop.MoInitMediaType(ref mediaType, waveFormatExSize); mediaType.SetWaveFormat(waveFormat); return mediaType; }
/// <summary> /// Sets the input type helper method /// </summary> /// <param name="inputStreamIndex">Input stream index</param> /// <param name="mediaType">Media type</param> /// <param name="flags">Flags (can be used to test rather than set)</param> private bool SetInputType(int inputStreamIndex, DmoMediaType mediaType, DmoSetTypeFlags flags) { int hResult = mediaObject.SetInputType(inputStreamIndex, ref mediaType, flags); if (hResult != HResult.S_OK) { if (hResult == (int)DmoHResults.DMO_E_INVALIDSTREAMINDEX) { throw new ArgumentException("Invalid stream index"); } if (hResult == (int)DmoHResults.DMO_E_TYPE_NOT_ACCEPTED) { Debug.WriteLine("Media type was not accepted"); } return false; } return true; }
public static extern int MoInitMediaType( [In, Out] ref DmoMediaType mediaType, int formatBlockBytes);
public static extern int MoFreeMediaType( [In] ref DmoMediaType mediaType);