public void CanCreateByteStreamFromIOStream() { var stream = new MemoryStream(); var comstream = new ComStream(stream); using (var byteStream = MediaFoundationCore.IStreamToByteStream(comstream)) { Assert.IsNotNull(byteStream); } }
public void CanCreateByteStreamFromIOStream() { MediaFoundationCore.Startup(); var stream = new MemoryStream(); var comstream = new ComStream(stream); var byteStream = MediaFoundationCore.IStreamToByteStream(comstream); Assert.IsNotNull(byteStream); Marshal.ReleaseComObject(byteStream); MediaFoundationCore.Shutdown(); }
/// <summary> /// Initializes a new instance of the <see cref="MediaFoundationDecoder" /> class. /// </summary> /// <param name="stream">Stream which provides the audio data to decode.</param> public MediaFoundationDecoder(Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); if (!stream.CanRead) throw new ArgumentException("Stream is not readable.", "stream"); stream = new ComStream(stream); _stream = stream; _byteStream = MediaFoundationCore.IStreamToByteStream((IStream) stream); _reader = Initialize(_byteStream); }
public void CanCreateSourceReaderFromIOStream() { MediaFoundationCore.Startup(); var stream = File.OpenRead(@"C:\Temp\test.mp3"); using (var comstream = new ComStream(stream)) { var byteStream = MediaFoundationCore.IStreamToByteStream(comstream); Assert.IsNotNull(byteStream); using (var reader = MediaFoundationCore.CreateSourceReaderFromByteStream(byteStream, IntPtr.Zero)) { Assert.IsNotNull(reader); } Marshal.ReleaseComObject(byteStream); } MediaFoundationCore.Shutdown(); }
public void CanCreateSourceReaderFromIOStream() { using(var stream = GlobalTestConfig.TestMp3AsStream()) using (var comstream = new ComStream(stream)) { using (var byteStream = MediaFoundationCore.IStreamToByteStream(comstream)) { Assert.IsNotNull(byteStream); using ( var reader = MediaFoundationCore.CreateSourceReaderFromByteStream(byteStream.BasePtr, IntPtr.Zero)) { Assert.IsNotNull(reader); } } } }
/// <summary> /// Sets and initializes the targetstream for the encoding process. /// </summary> /// <param name="stream">Stream which should be used as the targetstream.</param> /// <param name="inputMediaType">Mediatype of the raw input data to encode.</param> /// <param name="targetMediaType">Mediatype of the encoded data.</param> /// <param name="containerType">Container type which should be used.</param> protected void SetTargetStream(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType) { MFAttributes attributes = null; try { _targetBaseStream = new ComStream(stream); _targetStream = MediaFoundationCore.IStreamToByteStream(_targetBaseStream); attributes = new MFAttributes(2); attributes.SetUINT32(MediaFoundationAttributes.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1); attributes.SetGuid(MediaFoundationAttributes.MF_TRANSCODE_CONTAINERTYPE, containerType); _sinkWriter = new MFSinkWriter(_targetStream, attributes); _streamIndex = _sinkWriter.AddStream(targetMediaType); _sinkWriter.SetInputMediaType(_streamIndex, inputMediaType, null); _targetMediaType = targetMediaType; _sourceBytesPerSecond = inputMediaType.AverageBytesPerSecond; //initialize the sinkwriter _sinkWriter.BeginWriting(); } catch (Exception) { if (_sinkWriter != null) { _sinkWriter.Dispose(); _sinkWriter = null; } if (_targetStream != null) { _targetStream.Dispose(); _targetStream = null; } throw; } finally { if (attributes != null) attributes.Dispose(); } }