Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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");
            }
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
 /// <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));
 }
Ejemplo n.º 6
0
 /// <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);
     }
 }
Ejemplo n.º 7
0
 /// <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");
     }
 }
Ejemplo n.º 8
0
 /// <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);
 }
Ejemplo n.º 9
0
 /// <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;
 }
Ejemplo n.º 10
0
        /// <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;
        }
Ejemplo n.º 11
0
 public static extern int MoInitMediaType(
     [In, Out] ref DmoMediaType mediaType, int formatBlockBytes);
Ejemplo n.º 12
0
 public static extern int MoFreeMediaType(
     [In] ref DmoMediaType mediaType);