Beispiel #1
0
        /// <summary>
        ///     Creates a MediaType based on a given WaveFormat. Don't forget to call Free() for the returend MediaType.
        /// </summary>
        /// <param name="waveFormat">WaveFormat to create a MediaType from.</param>
        /// <returns>Dmo MediaType</returns>
        public static MediaType FromWaveFormat(WaveFormat waveFormat)
        {
            if (waveFormat == null)
                throw new ArgumentNullException("waveFormat");

            var mediaType = new MediaType();
            NativeMethods.MoInitMediaType(ref mediaType, Marshal.SizeOf(waveFormat));

            mediaType.MajorType = AudioSubTypes.MediaTypeAudio;
            mediaType.SubType = WaveFormatExtensible.SubTypeFromWaveFormat(waveFormat);
            mediaType.FixedSizeSamples = (mediaType.SubType == AudioSubTypes.IeeeFloat ||
                                          mediaType.SubType == AudioSubTypes.Pcm)
                ? 1
                : 0;
            mediaType.FormatType = FORMAT_WaveFormatEx;

            IntPtr hWaveFormat = Marshal.AllocHGlobal(Marshal.SizeOf(waveFormat));

            Marshal.StructureToPtr(waveFormat, hWaveFormat, false);

            if (hWaveFormat == IntPtr.Zero)
                throw new InvalidOperationException("hWaveFormat == IntPtr.Zero");
            if (mediaType.CbFormat < Marshal.SizeOf(waveFormat))
                throw new InvalidOperationException("No memory for Format reserved");
            mediaType.PtrFormat = hWaveFormat;

            return mediaType;
        }
Beispiel #2
0
 internal static unsafe int CalliMethodPtr(void* _basePtr, int streamIndex, MediaType mediaType,
     SetTypeFlags flags, void* p)
 {
     throw new NotImplementedException();
 }
Beispiel #3
0
        /// <summary>
        /// Tests whether the given MediaType is supported as OutputFormat.
        /// </summary>
        /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
        /// <param name="mediaType">MediaType</param>
        /// <returns>True = supported, False = not supported</returns>
        public bool SupportsOutputFormat(int outputStreamIndex, MediaType mediaType)
        {
            int result = SetOutputTypeNative(outputStreamIndex, mediaType, SetTypeFlags.TestOnly);
            switch ((DmoErrorCodes)result)
            {
                case (DmoErrorCodes)(HResult.S_OK):
                    return true;

                case DmoErrorCodes.DMO_E_INVALIDSTREAMINDEX:
                    throw new ArgumentOutOfRangeException("outputStreamIndex");
                case DmoErrorCodes.DMO_E_INVALIDTYPE:
                case DmoErrorCodes.DMO_E_TYPE_NOT_SET:
                case DmoErrorCodes.DMO_E_NOTACCEPTING:
                case DmoErrorCodes.DMO_E_TYPE_NOT_ACCEPTED:
                case DmoErrorCodes.DMO_E_NO_MORE_ITEMS:
                default:
                    return false;
            }
        }
Beispiel #4
0
 //----
 /// <summary>
 /// The SetOutputType method sets the media type on an output stream, or tests whether a media type is acceptable.
 /// </summary>
 /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
 /// <param name="mediaType">The new mediatype.</param>
 /// <param name="flags">Flags for setting the mediatype.</param>
 /// <returns>HRESULT</returns>
 public unsafe int SetOutputTypeNative(int outputStreamIndex, MediaType mediaType, SetTypeFlags flags)
 {
     return InteropCalls.CalliMethodPtr(_basePtr, outputStreamIndex, (void*)&mediaType, flags, ((void**)(*(void**)_basePtr))[9]);
 }
Beispiel #5
0
 /// <summary>
 /// The SetOutputType method sets the media type on an output stream, or tests whether a media type is acceptable.
 /// </summary>
 /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
 /// <param name="mediaType">The new mediatype.</param>
 /// <param name="flags">Flags for setting the mediatype.</param>
 public void SetOutputType(int outputStreamIndex, MediaType mediaType, SetTypeFlags flags)
 {
     int result = SetOutputTypeNative(outputStreamIndex, mediaType, flags);
     if ((flags & SetTypeFlags.TestOnly) != SetTypeFlags.TestOnly)
         DmoException.Try(result, n, "SetOutputType");
 }
Beispiel #6
0
 //--
 /// <summary>
 /// The SetInputType method sets the media type on an input stream, or tests whether a media type is acceptable.
 /// </summary>
 /// <param name="inputStreamIndex">Zero-based index of an input stream on the DMO.</param>
 /// <param name="mediaType">The new mediatype.</param>
 /// <param name="flags">Flags for setting the mediatype.</param>
 /// <returns>HRESULT</returns>
 public unsafe int SetInputTypeNative(int inputStreamIndex, MediaType mediaType, SetTypeFlags flags)
 {
     return InteropCalls.CalliMethodPtr(_basePtr,
         inputStreamIndex, ((void*)(&mediaType)), flags, ((void**)(*(void**)_basePtr))[8]);
 }
Beispiel #7
0
 /// <summary>
 /// The SetInputType method sets the media type on an input stream.
 /// </summary>
 /// <param name="inputStreamIndex">Zero-based index of an input stream on the DMO.</param>
 /// <param name="mediaType">The new mediatype.</param>
 /// <param name="flags">Flags for setting the mediatype.</param>
 public void SetInputType(int inputStreamIndex, MediaType mediaType, SetTypeFlags flags)
 {
     DmoException.Try(SetInputTypeNative(inputStreamIndex, mediaType, flags), n, "SetInputType");
 }
Beispiel #8
0
        //--
        /// <summary>
        /// Retrieves a preferred media type for a specified output stream.
        /// </summary>
        /// <param name="typeIndex">Zero-based index on the set of acceptable media types.</param>
        /// <param name="mediaType">Can be null to check whether the typeIndex argument is in range. If not, the errorcode will be DMO_E_NO_MORE_ITEMS (0x80040206).</param>
        /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
        /// <returns>HRESULT</returns>
        public unsafe int GetOutputTypeNative(int outputStreamIndex, int typeIndex, ref MediaType? mediaType)
        {
            void* ptr = (void*)IntPtr.Zero;
            MediaType mt = new MediaType();

            if (mediaType != null)
                ptr = &mt;

            int result = InteropCalls.CalliMethodPtr(_basePtr, outputStreamIndex, typeIndex, ptr, ((void**)(*(void**)_basePtr))[7]);

            if (mediaType != null)
                mediaType = mt;

            return result;
        }
Beispiel #9
0
 /// <summary>
 /// Retrieves a preferred media type for a specified output stream.
 /// </summary>
 /// <param name="typeIndex">Zero-based index on the set of acceptable media types.</param>
 /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
 public MediaType GetOutputType(int outputStreamIndex, int typeIndex)
 {
     MediaType? mediaType = new MediaType();
     DmoException.Try(GetOutputTypeNative(outputStreamIndex, typeIndex, ref mediaType), n, "GetOutputType");
     return mediaType.Value;
 }
Beispiel #10
0
 //---
 /// <summary>
 /// The GetOutputCurrentType method retrieves the media type that was set for an output stream, if any.
 /// </summary>
 /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
 /// <param name="mediaType">MediaType</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetOutputCurrentType(int outputStreamIndex, out MediaType mediaType)
 {
     fixed (void* p = &mediaType)
     {
         return InteropCalls.CalliMethodPtr(_basePtr, outputStreamIndex, p, ((void**)(*(void**)_basePtr))[11]);
     }
 }
Beispiel #11
0
        //----

        /// <summary>
        ///     Sets the <see cref="MediaType"/> on an output stream, or tests whether a <see cref="MediaType"/> is acceptable.
        /// </summary>
        /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
        /// <param name="mediaType">The new <see cref="MediaType"/>.</param>
        /// <param name="flags">Bitwise combination of zero or more flags from the <see cref="SetTypeFlags"/> enumeration.</param>
        /// <returns>HRESULT</returns>
        public unsafe int SetOutputTypeNative(int outputStreamIndex, MediaType mediaType, SetTypeFlags flags)
        {
            return(InteropCalls.CalliMethodPtr(UnsafeBasePtr, outputStreamIndex, &mediaType, flags,
                                               ((void **)(*(void **)UnsafeBasePtr))[9]));
        }
Beispiel #12
0
 /// <summary>
 ///     Sets the media type on an input stream.
 /// </summary>
 /// <param name="inputStreamIndex">Zero-based index of an input stream on the DMO.</param>
 /// <param name="mediaType">The new mediatype.</param>
 /// <param name="flags">Bitwise combination of zero or more flags from the <see cref="SetTypeFlags"/> enumeration.</param>
 public void SetInputType(int inputStreamIndex, MediaType mediaType, SetTypeFlags flags)
 {
     DmoException.Try(SetInputTypeNative(inputStreamIndex, mediaType, flags), n, "SetInputType");
 }
Beispiel #13
0
 /// <summary>
 ///     Retrieves a preferred media type for a specified output stream.
 /// </summary>
 /// <param name="typeIndex">Zero-based index on the set of acceptable media types.</param>
 /// <param name="outputStreamIndex">Zero-based index of an output stream on the DMO.</param>
 /// <returns>The preferred media type for the specified output stream.</returns>
 public MediaType GetOutputType(int outputStreamIndex, int typeIndex)
 {
     MediaType? mediaType = new MediaType();
     DmoException.Try(GetOutputTypeNative(outputStreamIndex, typeIndex, ref mediaType), n, "GetOutputType");
     Debug.Assert(mediaType != null, "No mediatype was returned.");
     return mediaType.Value;
 }
Beispiel #14
0
        //--
        /// <summary>
        ///     Retrieves a preferred media type for a specified input stream.
        /// </summary>
        /// <param name="typeIndex">Zero-based index on the set of acceptable media types.</param>
        /// <param name="mediaType">
        ///     Can be null to check whether the typeIndex argument is in range. If not, the errorcode will be
        ///     <see cref="DmoErrorCodes.DMO_E_NO_MORE_ITEMS"/> (0x80040206).
        /// </param>
        /// <param name="inputStreamIndex">Zero-based index of an input stream on the DMO.</param>
        /// <returns>HRESULT</returns>
        public unsafe int GetInputTypeNative(int inputStreamIndex, int typeIndex, ref MediaType? mediaType)
        {
            var ptr = (void*) IntPtr.Zero;
            var mt = new MediaType();

            if (mediaType != null)
                ptr = &mt;

            int result = InteropCalls.CalliMethodPtr(UnsafeBasePtr, inputStreamIndex, typeIndex, ptr,
                ((void**) (*(void**) UnsafeBasePtr))[6]);

            if (mediaType != null)
                mediaType = mt;

            return result;
        }
Beispiel #15
0
 //---
 /// <summary>
 ///     Retrieves the media type that was set for an input stream, if any.
 /// </summary>
 /// <param name="inputStreamIndex">Zero-based index of an input stream on the DMO.</param>
 /// <param name="mediaType">A variable that receives the retrieved media type of the specified input stream.</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetInputCurrentType(int inputStreamIndex, out MediaType mediaType)
 {
     fixed (void* p = &mediaType)
     {
         return InteropCalls.CalliMethodPtr(UnsafeBasePtr, inputStreamIndex, p, ((void**) (*(void**) UnsafeBasePtr))[10]);
     }
 }