/// <summary> /// Starts rendering to the target. /// </summary> /// <param name="videoPixelSize">The pixel size of the video.</param> protected override void StartRenderingInternal(Size2 videoPixelSize) { m_outStreamNet = base.TargetFile.OpenOutputStream(); m_outStream = new MF.ByteStream(m_outStreamNet); // Pass dummy filename as described here: // https://social.msdn.microsoft.com/forums/windowsapps/en-us/49bffa74-4e84-4fd6-9d67-42e8385611b8/video-sinkwriter-in-metro-app m_sinkWriter = MF.MediaFactory.CreateSinkWriterFromURL( this.DummyFileName, m_outStream.NativePointer, null); m_videoPixelSize = videoPixelSize; CreateMediaTarget(m_sinkWriter, m_videoPixelSize, out m_streamIndex); // Configure input using (MF.MediaType mediaTypeIn = new MF.MediaType()) { mediaTypeIn.Set <Guid>(MF.MediaTypeAttributeKeys.MajorType, MF.MediaTypeGuids.Video); mediaTypeIn.Set <Guid>(MF.MediaTypeAttributeKeys.Subtype, VIDEO_INPUT_FORMAT); mediaTypeIn.Set <int>(MF.MediaTypeAttributeKeys.InterlaceMode, (int)MF.VideoInterlaceMode.Progressive); mediaTypeIn.Set <long>(MF.MediaTypeAttributeKeys.FrameSize, MFHelper.GetMFEncodedIntsByValues(videoPixelSize.Width, videoPixelSize.Height)); mediaTypeIn.Set <long>(MF.MediaTypeAttributeKeys.FrameRate, MFHelper.GetMFEncodedIntsByValues(m_framerate, 1)); m_sinkWriter.SetInputMediaType(m_streamIndex, mediaTypeIn, null); } // Start writing the video file m_sinkWriter.BeginWriting(); // Set initial frame index m_frameIndex = -1; }
/// <summary> /// <p>[This documentation is preliminary and is subject to change.]</p><p><strong>Applies to: </strong>desktop apps | Metro style apps</p><p>Opens a media resource from a byte stream.</p> /// </summary> /// <param name="byteStreamRef"><dd> <p>A reference to the <strong><see cref="SharpDX.MediaFoundation.IByteStream"/></strong> interface of the byte stream.</p> </dd></param> /// <param name="uRLRef"><dd> <p>The URL of the byte stream.</p> </dd></param> /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns> /// <msdn-id>hh447956</msdn-id> /// <unmanaged>HRESULT IMFMediaEngineEx::SetSourceFromByteStream([In] IMFByteStream* pByteStream,[In] wchar_t* pURL)</unmanaged> /// <unmanaged-short>IMFMediaEngineEx::SetSourceFromByteStream</unmanaged-short> public void SetSourceFromByteStream(ByteStream byteStream, string url) { var bstrUrl = Utilities.StringToHGlobalUni(url); try { //var urlBstr = Marshal.StringToBSTR(url); SetSourceFromByteStream_(byteStream.NativePointer, bstrUrl); } finally { Marshal.FreeHGlobal(bstrUrl); } }
static void Main(string[] args) { // Select a File to play var openFileDialog = new OpenFileDialog { Title = "Select a music file", Filter = "Music Files(*.WMA;*.MP3;*.WAV)|*.WMA;*.MP3;*.WAV" }; var result = openFileDialog.ShowDialog(); if (result == DialogResult.Cancel) { return; } // Initialize MediaFoundation MediaManager.Startup(); // Creates the MediaEngineClassFactory var mediaEngineFactory = new MediaEngineClassFactory(); // Creates MediaEngine for AudioOnly var mediaEngine = new MediaEngine(mediaEngineFactory, null, MediaEngineCreateFlags.AudioOnly); // Register our PlayBackEvent mediaEngine.PlaybackEvent += OnPlaybackCallback; // Query for MediaEngineEx interface mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); // Opens the file var fileStream = openFileDialog.OpenFile(); // Create a ByteStream object from it var stream = new ByteStream(fileStream); // Creates an URL to the file var url = new Uri(openFileDialog.FileName, UriKind.RelativeOrAbsolute); // Set the source stream mediaEngineEx.SetSourceFromByteStream(stream, url.AbsoluteUri); // Wait for MediaEngine to be ready if (!eventReadyToPlay.WaitOne(1000)) { Console.WriteLine("Unexpected error: Unable to play this file"); } // Play the music mediaEngineEx.Play(); // Wait until music is stopped. while (!isMusicStopped) { Thread.Sleep(10); } }
/// <summary> /// Opens the given video file and plays it directly. /// </summary> /// <param name="videoLink">The link to the video file.</param> public async Task OpenAndShowVideoFileAsync(ResourceLink videoLink) { // Check for correct state if (this.State != MediaPlayerState.NothingToDo) { throw new InvalidOperationException("Unable to open video file as long as there is another video playing!"); } // Apply new state this.State = MediaPlayerState.Opening; try { // Create media session and a corresponding event listener obect for async events MF.MediaFactory.CreateMediaSession(null, out m_mediaSession); m_sessionEventHandler = MFSessionEventListener.AttachTo(m_mediaSession); m_sessionEventHandler.EndOfPresentation += OnSessionEventHandlerEndOfPresentationReached; // Create source object MF.SourceResolver sourceResolver = new MF.SourceResolver(); MF.ObjectType objType = MF.ObjectType.Invalid; m_videoSourceStreamNet = videoLink.OpenInputStream(); m_videoSourceStream = new MF.ByteStream(m_videoSourceStreamNet); SharpDX.ComObject objSource = sourceResolver.CreateObjectFromStream( m_videoSourceStream, "Dummy." + videoLink.FileExtension, MF.SourceResolverFlags.MediaSource, out objType); using (MF.MediaSource mediaSource = objSource.QueryInterface <MF.MediaSource>()) { GraphicsHelper.SafeDispose(ref objSource); GraphicsHelper.SafeDispose(ref sourceResolver); await ShowVideoAsync(mediaSource); } // Video opened successfully m_currentVideoLink = videoLink; m_currentCaptureDevice = null; this.State = MediaPlayerState.Playing; } catch (Exception) { // Unload all resources in case of an exception DisposeResources(); throw; } }
/// <summary> /// Create a topology to be played with a MediaSession from a filepath. /// </summary> internal static Topology CreateTopology(ByteStream mediaInputStream, out MediaSource mediaSource) { // collector to dispose all the created Media Foundation native objects. var collector = new ObjectCollector(); // Get the MediaSource object. var sourceResolver = new SourceResolver(); collector.Add(sourceResolver); ComObject mediaSourceObject; // Try to load music try { mediaSourceObject = sourceResolver.CreateObjectFromStream(mediaInputStream, null, SourceResolverFlags.MediaSource | SourceResolverFlags.ContentDoesNotHaveToMatchExtensionOrMimeType); } catch (SharpDXException) { collector.Dispose(); throw new InvalidOperationException("Music stream format not supported"); } Topology retTopo; try { mediaSource = mediaSourceObject.QueryInterface<MediaSource>(); collector.Add(mediaSourceObject); // Get the PresentationDescriptor PresentationDescriptor presDesc; mediaSource.CreatePresentationDescriptor(out presDesc); collector.Add(presDesc); // Create the topology MediaFactory.CreateTopology(out retTopo); for (var i = 0; i < presDesc.StreamDescriptorCount; i++) { Bool selected; StreamDescriptor desc; presDesc.GetStreamDescriptorByIndex(i, out selected, out desc); collector.Add(desc); if (selected) { // Test that the audio file data is valid and supported. var typeHandler = desc.MediaTypeHandler; collector.Add(typeHandler); var majorType = typeHandler.MajorType; if (majorType != MediaTypeGuids.Audio) throw new InvalidOperationException("The music stream is not a valid audio stream."); for (int mType = 0; mType < typeHandler.MediaTypeCount; mType++) { MediaType type; typeHandler.GetMediaTypeByIndex(mType, out type); collector.Add(type); var nbChannels = type.Get(MediaTypeAttributeKeys.AudioNumChannels); if (nbChannels > 2) throw new InvalidOperationException("The provided audio stream has more than 2 channels."); } // create the topology (source,...) TopologyNode sourceNode; MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out sourceNode); collector.Add(sourceNode); sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource); sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc); sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc); TopologyNode outputNode; MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode); collector.Add(outputNode); Activate activate; MediaFactory.CreateAudioRendererActivate(out activate); collector.Add(activate); outputNode.Object = activate; retTopo.AddNode(sourceNode); retTopo.AddNode(outputNode); sourceNode.ConnectOutput(0, outputNode, 0); } } } finally { collector.Dispose(); } return retTopo; }
private void ProcessPlayerClosed() { // The session finished to close, we have to dispose all related object. currentMusic = null; mediaSessionCallback.Dispose(); if (mediaSource != null) mediaSource.Shutdown(); if (mediaSession != null) mediaSession.Shutdown(); if (streamVolume != null) streamVolume.Dispose(); if (mediaSource != null) mediaSource.Dispose(); if (topology != null) topology.Dispose(); if (mediaSession != null) mediaSession.Dispose(); if (mediaInputByteStream != null) mediaInputByteStream.Dispose(); topology = null; streamVolume = null; mediaSession = null; mediaSource = null; mediaInputByteStream = null; mediaSessionCallback = null; isMusicPlayerReady = false; }
/// <summary> /// Load a new music into the media session. That is create a new session and a new topology and set the topology of the session. /// </summary> /// <param name="music"></param> private void LoadNewMusic(SoundMusic music) { if (currentMusic != null || mediaSession != null) throw new AudioSystemInternalException("State of the audio engine invalid at the entry of LoadNewMusic."); music.Stream.Position = 0; mediaInputByteStream = new ByteStream(music.Stream); topology = CreateTopology(mediaInputByteStream, out mediaSource); MediaFactory.CreateMediaSession(null, out mediaSession); mediaSessionCallback = new MediaSessionCallback(mediaSession, OnMediaSessionEvent); mediaSession.SetTopology(SessionSetTopologyFlags.None, topology); currentMusic = music; }
public void SetBytestream(IRandomAccessStream streamHandle) { byteStream = new ByteStream(streamHandle); mediaEngineEx.SetSourceFromByteStream(byteStream, Url); }
/// <summary> /// Initializes a new instance of the <see cref="MediaFoundationVideoReader"/> class. /// </summary> /// <param name="videoSource">The source video file.</param> public MediaFoundationVideoReader(ResourceLink videoSource) { videoSource.EnsureNotNull(nameof(videoSource)); try { m_videoSource = videoSource; // Create the source reader using (MF.MediaAttributes mediaAttributes = new MF.MediaAttributes(1)) { // We need the 'EnableVideoProcessing' attribute because of the RGB32 format // see (lowest post): http://msdn.developer-works.com/article/11388495/How+to+use+SourceReader+(for+H.264+to+RGB+conversion)%3F mediaAttributes.Set(MF.SourceReaderAttributeKeys.EnableVideoProcessing, 1); mediaAttributes.Set(MF.SourceReaderAttributeKeys.DisableDxva, 1); // Wrap the .net stream to a MF Bytestream m_videoSourceStreamNet = m_videoSource.OpenInputStream(); m_videoSourceStream = new MF.ByteStream(m_videoSourceStreamNet); try { using (MF.MediaAttributes byteStreamAttributes = m_videoSourceStream.QueryInterface <MF.MediaAttributes>()) { byteStreamAttributes.Set(MF.ByteStreamAttributeKeys.OriginName, "Dummy." + videoSource.FileExtension); } } catch (SharpDXException) { // The interface MF.MediaAttributes is not available on some platforms // (occured during tests on Windows 7 without Platform Update) } // Create the sourcereader by custom native method (needed because of the ByteStream arg) IntPtr sourceReaderPointer = IntPtr.Zero; SharpDX.Result sdxResult = NativeMethods.MFCreateSourceReaderFromByteStream_Native( m_videoSourceStream.NativePointer, mediaAttributes.NativePointer, out sourceReaderPointer); sdxResult.CheckError(); m_sourceReader = new MF.SourceReader(sourceReaderPointer); } // Apply source configuration using (MF.MediaType mediaType = new MF.MediaType()) { mediaType.Set(MF.MediaTypeAttributeKeys.MajorType, MF.MediaTypeGuids.Video); mediaType.Set(MF.MediaTypeAttributeKeys.Subtype, MF.VideoFormatGuids.Rgb32); m_sourceReader.SetCurrentMediaType( MF.SourceReaderIndex.FirstVideoStream, mediaType); m_sourceReader.SetStreamSelection(MF.SourceReaderIndex.FirstVideoStream, new SharpDX.Mathematics.Interop.RawBool(true)); } // Read some information about the source using (MF.MediaType mediaType = m_sourceReader.GetCurrentMediaType(MF.SourceReaderIndex.FirstVideoStream)) { long frameSizeLong = mediaType.Get(MF.MediaTypeAttributeKeys.FrameSize); m_frameSize = new Size2(MFHelper.GetValuesByMFEncodedInts(frameSizeLong)); } // Get additional propertie3s m_durationLong = m_sourceReader.GetPresentationAttribute( MF.SourceReaderIndex.MediaSource, MF.PresentationDescriptionAttributeKeys.Duration); m_characteristics = (MediaSourceCharacteristics_Internal)m_sourceReader.GetPresentationAttribute( MF.SourceReaderIndex.MediaSource, MF.SourceReaderAttributeKeys.MediaSourceCharacteristics); } catch (Exception) { this.Dispose(); throw; } }
static void Main(string[] args) { // Select a File to play var openFileDialog = new OpenFileDialog { Title = "Select a file", Filter = "Media Files(*.WMV;*.MP4;*.AVI)|*.WMV;*.MP4;*.AVI" }; var result = openFileDialog.ShowDialog(); if (result == DialogResult.Cancel) { return; } // Initialize MediaFoundation MediaManager.Startup(); var renderForm = new SharpDX.Windows.RenderForm(); device = CreateDeviceForVideo(out dxgiManager); // Creates the MediaEngineClassFactory var mediaEngineFactory = new MediaEngineClassFactory(); //Assign our dxgi manager, and set format to bgra MediaEngineAttributes attr = new MediaEngineAttributes(); attr.VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm; attr.DxgiManager = dxgiManager; // Creates MediaEngine for AudioOnly var mediaEngine = new MediaEngine(mediaEngineFactory, attr, MediaEngineCreateFlags.None); // Register our PlayBackEvent mediaEngine.PlaybackEvent += OnPlaybackCallback; // Query for MediaEngineEx interface mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); // Opens the file var fileStream = openFileDialog.OpenFile(); // Create a ByteStream object from it var stream = new ByteStream(fileStream); // Creates an URL to the file var url = new Uri(openFileDialog.FileName, UriKind.RelativeOrAbsolute); // Set the source stream mediaEngineEx.SetSourceFromByteStream(stream, url.AbsoluteUri); // Wait for MediaEngine to be ready if (!eventReadyToPlay.WaitOne(1000)) { Console.WriteLine("Unexpected error: Unable to play this file"); } //Create our swapchain swapChain = CreateSwapChain(device, renderForm.Handle); //Get DXGI surface to be used by our media engine var texture = Texture2D.FromSwapChain<Texture2D>(swapChain, 0); var surface = texture.QueryInterface<SharpDX.DXGI.Surface>(); //Get our video size int w, h; mediaEngine.GetNativeVideoSize(out w, out h); // Play the music mediaEngineEx.Play(); long ts; RenderLoop.Run(renderForm, () => { //Transfer frame if a new one is available if (mediaEngine.OnVideoStreamTick(out ts)) { mediaEngine.TransferVideoFrame(surface, null, new SharpDX.Rectangle(0, 0, w, h), null); } swapChain.Present(1, SharpDX.DXGI.PresentFlags.None); }); mediaEngine.Shutdown(); swapChain.Dispose(); device.Dispose(); }
/// <summary> /// /// </summary> private void PlatformInitialize( byte[] bytes, Stream stream, string url ) { if (Topology != null) { return; } MediaFactory.CreateTopology(out _topology); SharpDX.MediaFoundation.MediaSource mediaSource; { SourceResolver resolver = new SourceResolver(); ObjectType otype; ComObject source = null; if (url!=null) { source = resolver.CreateObjectFromURL(url, SourceResolverFlags.MediaSource, null, out otype); } if (stream!=null) { var bs = new ByteStream( stream ); source = resolver.CreateObjectFromStream(bs, null, SourceResolverFlags.MediaSource, null, out otype); } if (bytes!=null) { var bs = new ByteStream( bytes ); source = resolver.CreateObjectFromStream(bs, null, SourceResolverFlags.MediaSource|SourceResolverFlags.ContentDoesNotHaveToMatchExtensionOrMimeType, null, out otype); } if (source==null) { throw new ArgumentException("'stream' and 'url' are null!"); } mediaSource = source.QueryInterface<SharpDX.MediaFoundation.MediaSource>(); resolver.Dispose(); source.Dispose(); } PresentationDescriptor presDesc; mediaSource.CreatePresentationDescriptor(out presDesc); for (var i = 0; i < presDesc.StreamDescriptorCount; i++) { RawBool selected = false; StreamDescriptor desc; presDesc.GetStreamDescriptorByIndex(i, out selected, out desc); if (selected) { TopologyNode sourceNode; MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out sourceNode); sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource); sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc); sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc); TopologyNode outputNode; MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode); var majorType = desc.MediaTypeHandler.MajorType; if (majorType == MediaTypeGuids.Video) { Activate activate; sampleGrabber = new VideoSampleGrabber(); _mediaType = new MediaType(); _mediaType.Set(MediaTypeAttributeKeys.MajorType, MediaTypeGuids.Video); // Specify that we want the data to come in as RGB32. _mediaType.Set(MediaTypeAttributeKeys.Subtype, new Guid("00000016-0000-0010-8000-00AA00389B71")); MediaFactory.CreateSampleGrabberSinkActivate(_mediaType, SampleGrabber, out activate); outputNode.Object = activate; long frameSize = desc.MediaTypeHandler.CurrentMediaType.Get<long>(MediaTypeAttributeKeys.FrameSize); Width = (int)(frameSize >> 32); Height = (int) (frameSize & 0x0000FFFF); } if (majorType == MediaTypeGuids.Audio) { Activate activate; MediaFactory.CreateAudioRendererActivate(out activate); outputNode.Object = activate; } _topology.AddNode(sourceNode); _topology.AddNode(outputNode); sourceNode.ConnectOutput(0, outputNode, 0); Duration = new TimeSpan(presDesc.Get<long>(PresentationDescriptionAttributeKeys.Duration)); sourceNode.Dispose(); outputNode.Dispose(); } desc.Dispose(); } presDesc.Dispose(); mediaSource.Dispose(); videoFrame = new DynamicTexture(Game.Instance.RenderSystem, Width, Height, typeof(ColorBGRA), false, false); }
/// <summary> /// Creates the source reader from a byte stream. /// </summary> /// <param name="buffer"><dd> <p>A reference to the <strong><see cref="SharpDX.MediaFoundation.IByteStream"/></strong> interface of a byte stream. This byte stream will provide the source data for the source reader.</p> </dd></param> /// <param name="attributes"><dd> <p>Pointer to the <strong><see cref="SharpDX.MediaFoundation.MediaAttributes"/></strong> interface. You can use this parameter to configure the source reader. For more information, see Source Reader Attributes. This parameter can be <strong><c>null</c></strong>.</p> </dd></param> /// <remarks> /// <p>Call <strong>CoInitialize(Ex)</strong> and <strong><see cref="SharpDX.MediaFoundation.MediaFactory.Startup"/></strong> before calling this function.</p><p> Internally, the source reader calls the <strong><see cref="SharpDX.MediaFoundation.SourceResolver.CreateObjectFromByteStream_"/></strong> method to create a media source from the byte stream. Therefore, a byte-stream handler must be registered for the byte stream. For more information about byte-stream handlers, see Scheme Handlers and Byte-Stream Handlers. </p><p>This function is available on Windows?Vista if Platform Update Supplement for Windows?Vista is installed.</p> /// </remarks> /// <msdn-id>dd388106</msdn-id> /// <unmanaged>HRESULT MFCreateSourceReaderFromByteStream([In] IMFByteStream* pByteStream,[In, Optional] IMFAttributes* pAttributes,[Out, Fast] IMFSourceReader** ppSourceReader)</unmanaged> /// <unmanaged-short>MFCreateSourceReaderFromByteStream</unmanaged-short> public SourceReader(byte[] buffer, MediaAttributes attributes = null) { byteStream = new ByteStream(new MemoryStream(buffer)); MediaFactory.CreateSourceReaderFromByteStream(byteStream.NativePointer, attributes, this); }
/// <summary> /// Creates the source reader from a byte stream. /// </summary> /// <param name="comStream"><dd> <p>A reference to the <strong><see cref="SharpDX.MediaFoundation.IByteStream"/></strong> interface of a byte stream. This byte stream will provide the source data for the source reader.</p> </dd></param> /// <param name="attributes"><dd> <p>Pointer to the <strong><see cref="SharpDX.MediaFoundation.MediaAttributes"/></strong> interface. You can use this parameter to configure the source reader. For more information, see Source Reader Attributes. This parameter can be <strong><c>null</c></strong>.</p> </dd></param> /// <remarks> /// <p>Call <strong>CoInitialize(Ex)</strong> and <strong><see cref="SharpDX.MediaFoundation.MediaFactory.Startup"/></strong> before calling this function.</p><p> Internally, the source reader calls the <strong><see cref="SharpDX.MediaFoundation.SourceResolver.CreateObjectFromByteStream_"/></strong> method to create a media source from the byte stream. Therefore, a byte-stream handler must be registered for the byte stream. For more information about byte-stream handlers, see Scheme Handlers and Byte-Stream Handlers. </p><p>This function is available on Windows?Vista if Platform Update Supplement for Windows?Vista is installed.</p> /// </remarks> /// <msdn-id>dd388106</msdn-id> /// <unmanaged>HRESULT MFCreateSourceReaderFromByteStream([In] IMFByteStream* pByteStream,[In, Optional] IMFAttributes* pAttributes,[Out, Fast] IMFSourceReader** ppSourceReader)</unmanaged> /// <unmanaged-short>MFCreateSourceReaderFromByteStream</unmanaged-short> public SourceReader(SharpDX.Win32.ComStream comStream, MediaAttributes attributes = null) { byteStream = new ByteStream(comStream); MediaFactory.CreateSourceReaderFromByteStream(byteStream.NativePointer, attributes, this); }
/// <summary> /// Creates the source reader from a byte stream. /// </summary> /// <param name="buffer"><dd> <p>A reference to the <strong><see cref="SharpDX.MediaFoundation.IByteStream"/></strong> interface of a byte stream. This byte stream will provide the source data for the source reader.</p> </dd></param> /// <param name="attributes"><dd> <p>Pointer to the <strong><see cref="SharpDX.MediaFoundation.MediaAttributes"/></strong> interface. You can use this parameter to configure the source reader. For more information, see Source Reader Attributes. This parameter can be <strong><c>null</c></strong>.</p> </dd></param> /// <remarks> /// <p>Call <strong>CoInitialize(Ex)</strong> and <strong><see cref="SharpDX.MediaFoundation.MediaFactory.Startup"/></strong> before calling this function.</p><p> Internally, the source reader calls the <strong><see cref="SharpDX.MediaFoundation.SourceResolver.CreateObjectFromByteStream_"/></strong> method to create a media source from the byte stream. Therefore, a byte-stream handler must be registered for the byte stream. For more information about byte-stream handlers, see Scheme Handlers and Byte-Stream Handlers. </p><p>This function is available on Windows?Vista if Platform Update Supplement for Windows?Vista is installed.</p> /// </remarks> /// <msdn-id>dd388106</msdn-id> /// <unmanaged>HRESULT MFCreateSourceReaderFromByteStream([In] IMFByteStream* pByteStream,[In, Optional] IMFAttributes* pAttributes,[Out, Fast] IMFSourceReader** ppSourceReader)</unmanaged> /// <unmanaged-short>MFCreateSourceReaderFromByteStream</unmanaged-short> public SourceReader(IRandomAccessStream buffer, MediaAttributes attributes = null) { byteStream = new ByteStream(buffer); MediaFactory.CreateSourceReaderFromByteStream(byteStream.NativePointer, attributes, this); }
/// <summary> /// <p>Specifies a byte stream that will receive the data for the recording.</p> /// </summary> /// <param name="byteStreamRef"><dd> <p>A reference to the <strong><see cref="SharpDX.MediaFoundation.IByteStream"/></strong> interface of a byte stream. The byte stream must be writable.</p> </dd></param> /// <param name="guidContainerType"><dd> <p>A <see cref="System.Guid"/> that specifies the file container type. Possible values are documented in the <see cref="SharpDX.MediaFoundation.TranscodeAttributeKeys.TranscodeContainertype"/> attribute.</p> </dd></param> /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns> /// <remarks> /// <p>Calling this method overrides any previous call to <strong><see cref="SharpDX.MediaFoundation.CaptureRecordSink.SetOutputFileName"/></strong> or <strong><see cref="SharpDX.MediaFoundation.CaptureRecordSink.SetSampleCallback_"/></strong>.</p> /// </remarks> /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='IMFCaptureRecordSink::SetOutputByteStream']/*"/> /// <msdn-id>hh447878</msdn-id> /// <unmanaged>HRESULT IMFCaptureRecordSink::SetOutputByteStream([In] IMFByteStream* pByteStream,[In] const GUID& guidContainerType)</unmanaged> /// <unmanaged-short>IMFCaptureRecordSink::SetOutputByteStream</unmanaged-short> public void SetOutputByteStream(ByteStream stream, Guid containerType) { SetOutputByteStream_(stream.NativePointer, containerType); }