/// <summary>
        /// Creates the reader (overridable by )
        /// </summary>
        protected virtual IMFSourceReader CreateReader(MediaFoundationReaderSettings settings)
        {
            IMFSourceReader reader;

            MediaFoundationInterop.MFCreateSourceReaderFromURL(file, null, out reader);
            reader.SetStreamSelection(MediaFoundationInterop.MF_SOURCE_READER_ALL_STREAMS, false);
            reader.SetStreamSelection(MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);

            // Create a partial media type indicating that we want uncompressed PCM audio

            var partialMediaType = new MediaType();

            partialMediaType.MajorType = MediaTypes.MFMediaType_Audio;
            partialMediaType.SubType   = settings.RequestFloatOutput ? AudioSubtypes.MFAudioFormat_Float : AudioSubtypes.MFAudioFormat_PCM;

            var currentMediaType = GetCurrentMediaType(reader);

            // mono, low sample rate files can go wrong on Windows 10 unless we specify here
            partialMediaType.ChannelCount = currentMediaType.ChannelCount;
            partialMediaType.SampleRate   = currentMediaType.SampleRate;

            // set the media type
            // can return MF_E_INVALIDMEDIATYPE if not supported
            reader.SetCurrentMediaType(MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, IntPtr.Zero, partialMediaType.MediaFoundationObject);

            Marshal.ReleaseComObject(currentMediaType.MediaFoundationObject);
            return(reader);
        }
        /// <summary>
        /// Creates the reader (overridable by )
        /// </summary>
        protected virtual IMFSourceReader CreateReader(MediaFoundationReaderSettings settings)
        {
            IMFSourceReader reader;

            // If the file exists.
            if (!String.IsNullOrEmpty(file))
            {
                MediaFoundationInterop.MFCreateSourceReaderFromURL(file, null, out reader);
            }
            else
            {
                IMFByteStream byteStream = MediaFoundationApi.CreateByteStreamFromStream(_inputStream);
                MediaFoundationInterop.MFCreateSourceReaderFromByteStream(byteStream, null, out reader);
            }

            reader.SetStreamSelection(MediaFoundationInterop.MF_SOURCE_READER_ALL_STREAMS, false);
            reader.SetStreamSelection(MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);

            // Create a partial media type indicating that we want uncompressed PCM audio

            var partialMediaType = new MediaType();

            partialMediaType.MajorType = MediaTypes.MFMediaType_Audio;
            partialMediaType.SubType   = settings.RequestFloatOutput ? AudioSubtypes.MFAudioFormat_Float : AudioSubtypes.MFAudioFormat_PCM;

            // set the media type
            // can return MF_E_INVALIDMEDIATYPE if not supported
            reader.SetCurrentMediaType(MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, IntPtr.Zero, partialMediaType.MediaFoundationObject);
            return(reader);
        }
Exemplo n.º 3
0
        protected virtual IMFSourceReader CreateReader(MediaFoundationReader.MediaFoundationReaderSettings settings)
        {
            IMFSourceReader imfsourceReader;

            MediaFoundationInterop.MFCreateSourceReaderFromURL(this.file, null, out imfsourceReader);
            imfsourceReader.SetStreamSelection(-2, false);
            imfsourceReader.SetStreamSelection(-3, true);
            MediaType mediaType = new MediaType();

            mediaType.MajorType = MediaTypes.MFMediaType_Audio;
            mediaType.SubType   = (settings.RequestFloatOutput ? AudioSubtypes.MFAudioFormat_Float : AudioSubtypes.MFAudioFormat_PCM);
            imfsourceReader.SetCurrentMediaType(-3, IntPtr.Zero, mediaType.MediaFoundationObject);
            return(imfsourceReader);
        }
Exemplo n.º 4
0
 public Video(string path, bool loop = false)
 {
     _path = path;
     Loop  = loop;
     // Get the frame size
     MediaFoundationInterop.MFCreateSourceReaderFromURL(_path, null, out IMFSourceReader reader);
     reader.GetNativeMediaType(MediaFoundationInterop.MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, out IMFMediaType nativeType);
     nativeType.GetUINT64(MF_MT_FRAME_SIZE, out long size);
     _videoWidth  = (int)((size >> 32) & 0x7FFFFFFF);
     _videoHeight = (int)(size & 0x7FFFFFFF);
     _length      = GetLength(reader);
     Marshal.ReleaseComObject(nativeType);
     Marshal.ReleaseComObject(reader);
     Pack();
 }