示例#1
0
        /// <summary>
        /// retrieves the media type that was set for an output stream, if any
        /// </summary>
        /// <param name="outputStreamIndex">Output stream index</param>
        /// <returns>DMO Media Type or null if no more available</returns>
        public DmoMediaType GetOutputCurrentType(int outputStreamIndex)
        {
            DmoMediaType mediaType;
            int          hresult = mediaObject.GetOutputCurrentType(outputStreamIndex, out mediaType);

            if (hresult == HResult.S_OK)
            {
                // this frees the format (if present)
                // we should therefore come up with a way of marshaling the format
                // into a completely managed structure
                DmoInterop.MoFreeMediaType(ref mediaType);
                return(mediaType);
            }
            else
            {
                if (hresult == (int)DmoHResults.DMO_E_TYPE_NOT_SET)
                {
                    throw new InvalidOperationException("Media type was not set.");
                }
                else
                {
                    throw Marshal.GetExceptionForHR(hresult);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Tests if the specified Wave Format is supported for output
        /// n.b. may need to set the input type first
        /// </summary>
        /// <param name="outputStreamIndex">Output stream index</param>
        /// <param name="waveFormat">Wave format</param>
        /// <returns>True if supported</returns>
        public bool SupportsOutputWaveFormat(int outputStreamIndex, WaveFormat waveFormat)
        {
            DmoMediaType mediaType = CreateDmoMediaTypeForWaveFormat(waveFormat);
            bool         supported = SetOutputType(outputStreamIndex, mediaType, DmoSetTypeFlags.DMO_SET_TYPEF_TEST_ONLY);

            DmoInterop.MoFreeMediaType(ref mediaType);
            return(supported);
        }
示例#3
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);
        }
示例#4
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");
            }
        }
示例#5
0
        private static IEnumerable <DmoDescriptor> GetDmos(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(new DmoDescriptor(name, guid));
                }
            } while (itemsFetched > 0);
        }
示例#6
0
 /// <summary>
 /// Gets the DMO Media Output type
 /// </summary>
 /// <param name="outputStream">The output stream</param>
 /// <param name="outputTypeIndex">Output type index</param>
 /// <returns>DMO Media Type or null if no more available</returns>
 public DmoMediaType?GetOutputType(int outputStream, int outputTypeIndex)
 {
     try
     {
         DmoMediaType mediaType;
         int          hresult = mediaObject.GetOutputType(outputStream, outputTypeIndex, out mediaType);
         if (hresult == HResult.S_OK)
         {
             // this frees the format (if present)
             // we should therefore come up with a way of marshaling the format
             // into a completely managed structure
             DmoInterop.MoFreeMediaType(ref mediaType);
             return(mediaType);
         }
     }
     catch (COMException e)
     {
         if (e.GetHResult() != (int)DmoHResults.DMO_E_NO_MORE_ITEMS)
         {
             throw;
         }
     }
     return(null);
 }