Example #1
0
        private MFSourceReader Initialize(MFSourceReader reader)
        {
            MediaFoundationCore.Startup();

            try
            {
                reader.SetStreamSelection(MFInterops.MF_SOURCE_READER_ALL_STREAMS, false);
                reader.SetStreamSelection(MFInterops.MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);

                using (var mediaType = MFMediaType.CreateEmpty())
                {
                    mediaType.MajorType = MediaTypes.MediaTypeAudio;
                    mediaType.SubType   = MediaTypes.MEDIATYPE_Pcm; //variable??

                    reader.SetCurrentMediaType(MFInterops.MF_SOURCE_READER_FIRST_AUDIO_STREAM, mediaType);
                }

                using (var currentMediaType = reader.GetCurrentMediaType(MFInterops.MF_SOURCE_READER_FIRST_AUDIO_STREAM))
                {
                    if (currentMediaType.MajorType != MediaTypes.MediaTypeAudio)
                    {
                        throw new InvalidOperationException(String.Format("Invalid Majortype set on sourcereader: {0}.", currentMediaType.MajorType.ToString()));
                    }

                    AudioEncoding encoding;
                    if (currentMediaType.SubType == MediaTypes.MEDIATYPE_Pcm)
                    {
                        encoding = AudioEncoding.Pcm;
                    }
                    else if (currentMediaType.SubType == MediaTypes.MEDIATYPE_IeeeFloat)
                    {
                        encoding = AudioEncoding.IeeeFloat;
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format("Invalid Subtype set on sourcereader: {0}.", currentMediaType.SubType.ToString()));
                    }

                    _waveFormat = new WaveFormat(currentMediaType.SampleRate, currentMediaType.BitsPerSample, currentMediaType.Channels, encoding);
                }

                reader.SetStreamSelection(MFInterops.MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);

                if (_hasFixedLength)
                {
                    _length = GetLength(reader);
                }

                return(reader);
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
        }
Example #2
0
        public MediaFoundationDecoder(string url)
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("filename");
            }

            _hasFixedLength = true;

            MediaFoundationCore.Startup();
            _reader = Initialize(MediaFoundationCore.CreateSourceReaderFromUrl(url));
        }
Example #3
0
 public static MFMediaType FromWaveFormat(WaveFormat waveFormat)
 {
     MediaFoundationCore.Startup();
     return(MediaFoundationCore.MediaTypeFromWaveFormat(waveFormat));
 }
Example #4
0
 public static MFMediaType CreateEmpty()
 {
     MediaFoundationCore.Startup();
     return(MediaFoundationCore.CreateMediaType());
 }
 static MediaFoundationEncoder()
 {
     MediaFoundationCore.Startup();
 }
Example #6
0
 static MediaFoundationDecoder()
 {
     MediaFoundationCore.Startup(); //make sure that the MediaFoundation is started up.
 }
Example #7
0
 private MFSourceReader Initialize(IMFByteStream stream)
 {
     MediaFoundationCore.Startup();
     return(Initialize(MediaFoundationCore.CreateSourceReaderFromByteStream(stream, IntPtr.Zero)));
 }