public static void MFTranscodeGetAudioOutputAvailableTypes(
     Guid subType,
     uint flags,
     uint codecConfig,
     out IMFCollection availableTypes)
 {
     int result = ExternMFTranscodeGetAudioOutputAvailableTypes(subType, flags, codecConfig, out availableTypes);
     if (result != 0)
     {
         throw new COMException("Exception from HRESULT: 0x" + result.ToString("X", System.Globalization.NumberFormatInfo.InvariantInfo) + "(MFTranscodeGetAudioOutputAvailableTypes)", result);
     }
 }
 public static extern void MFTranscodeGetAudioOutputAvailableTypes(
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid guidSubType,
     [In] _MFT_ENUM_FLAG dwMFTFlags,
     [In] IMFAttributes pCodecConfig,
     [Out, MarshalAs(UnmanagedType.Interface)] out IMFCollection ppAvailableTypes);
        private IMFMediaType CreateTargetAudioMediaType()
        {
            IMFMediaType mediaType = null;

            if (audioOutput.Subtype.Equals(new Guid(Consts.MFAudioFormat_AAC)))
            {
                // Create the AAC media type
                MFHelper.MFCreateMediaType(out mediaType);

                mediaType.SetGUID(new Guid(Consts.MF_MT_MAJOR_TYPE), new Guid(Consts.MFMediaType_Audio));

                mediaType.SetGUID(new Guid(Consts.MF_MT_SUBTYPE), this.audioOutput.Subtype);
                mediaType.SetUINT32(new Guid(Consts.MF_MT_AUDIO_AVG_BYTES_PER_SECOND), this.audioOutput.AvgBytePerSecond);
                mediaType.SetUINT32(new Guid(Consts.MF_MT_AUDIO_NUM_CHANNELS), this.audioOutput.NumOfChannels);
                mediaType.SetUINT32(new Guid(Consts.MF_MT_AUDIO_SAMPLES_PER_SECOND), this.audioOutput.SamplesPerSecond);
                mediaType.SetUINT32(new Guid(Consts.MF_MT_AUDIO_BLOCK_ALIGNMENT), this.audioOutput.BlockAlignment);
                mediaType.SetUINT32(new Guid(Consts.MF_MT_AUDIO_BITS_PER_SAMPLE), this.audioOutput.BitsPerSample);
            }
            else
            {
                // Create the WMA media type
                uint   codecConfig         = 0;
                uint   elementsNumber      = 0;
                uint   selectedType        = 0;
                int    avgBitrateDiff      = int.MaxValue;
                uint   avgBytePerSecond    = uint.MaxValue;
                object supportedAttributes = null;

                // Get the available audio ouput types for the required sub type
                IMFCollection availableTypes = null;
                MFHelper.MFTranscodeGetAudioOutputAvailableTypes(audioOutput.Subtype, (uint)Enums.MFT_ENUM_FLAG.MFT_ENUM_FLAG_ALL, codecConfig, out availableTypes);

                // Get the number of types
                availableTypes.GetElementCount(out elementsNumber);

                for (uint elementIndex = 0; elementIndex < elementsNumber; elementIndex++)
                {
                    // Get the next element
                    availableTypes.GetElement(elementIndex, out supportedAttributes);
                    mediaType = (IMFMediaType)supportedAttributes;

                    // Get the byte per second
                    mediaType.GetUINT32(new Guid(Consts.MF_MT_AUDIO_AVG_BYTES_PER_SECOND), out avgBytePerSecond);

                    // If this is better than the last one found remember the index
                    if (Math.Abs((int)avgBytePerSecond - (int)audioOutput.AvgBytePerSecond) < avgBitrateDiff)
                    {
                        selectedType   = elementIndex;
                        avgBitrateDiff = Math.Abs((int)avgBytePerSecond - (int)audioOutput.AvgBytePerSecond);
                    }

                    mediaType = null;
                }

                // Get the best audio type found
                availableTypes.GetElement(selectedType, out supportedAttributes);
                mediaType = (IMFMediaType)supportedAttributes;
            }

            return(mediaType);
        }
Beispiel #4
0
 private static extern int ExternMFTranscodeGetAudioOutputAvailableTypes(
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid guidSubType,
     [In] uint dwMFTFlags,
     [In] uint pCodecConfig,
     [Out, MarshalAs(UnmanagedType.Interface)] out IMFCollection ppAvailableTypes);
Beispiel #5
0
 public static extern HResult MFCreateAggregateSource(
     IMFCollection pSourceCollection,
     out IMFMediaSource ppAggSource
     );
Beispiel #6
0
 public static extern HResult MFCreateCollection(
     out IMFCollection ppIMFCollection
     );