private static void CreateMediaSinkActivate(PresentationDescriptor pd, StreamDescriptor sd, int streamIndex, IntPtr hVideoWnd, out Activate?activate)
        {
            var handler   = sd.MediaTypeHandler;
            var majorType = handler.MajorType;

            if (majorType == MediaTypeGuids.Audio)
            {
                MediaFactory.CreateAudioRendererActivate(out activate);
            }
            else if (majorType == MediaTypeGuids.Video)
            {
                MediaFactory.CreateVideoRendererActivate(hVideoWnd, out activate);
            }
            else
            {
                pd.DeselectStream(streamIndex);
                activate = null;
            }
        }
Exemple #2
0
        private TopologyNode CreateOutputNode(StreamDescriptor streamDescriptor, IntPtr hwnd)
        {
            TopologyNode outputNode;
            Activate     rendererActivate;

            if (streamDescriptor.MediaTypeHandler.MajorType == MediaTypeGuids.Audio)
            {
                MediaFactory.CreateAudioRendererActivate(out rendererActivate);
            }
            else if (streamDescriptor.MediaTypeHandler.MajorType == MediaTypeGuids.Video)
            {
                MediaFactory.CreateVideoRendererActivate(hwnd, out rendererActivate);
            }
            else
            {
                throw new Exception("Bad stream");
            }

            MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode);
            outputNode.Object = rendererActivate;

            return(outputNode);
        }
Exemple #3
0
        private void PlatformInitialize()
        {
            if (Topology != null)
            {
                return;
            }

            MediaManagerState.CheckStartup();

            MediaFactory.CreateTopology(out _topology);

            SharpDX.MediaFoundation.MediaSource mediaSource;
            {
                SourceResolver resolver = new SourceResolver();

                ObjectType otype;
                ComObject  source = resolver.CreateObjectFromURL(FileName, SourceResolverFlags.MediaSource, null, out otype);
                mediaSource = source.QueryInterface <SharpDX.MediaFoundation.MediaSource>();
                resolver.Dispose();
                source.Dispose();
            }

            PresentationDescriptor presDesc;

            mediaSource.CreatePresentationDescriptor(out presDesc);

            for (var i = 0; i < presDesc.StreamDescriptorCount; i++)
            {
                SharpDX.Mathematics.Interop.RawBool selected;
                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;
                    }

                    if (majorType == MediaTypeGuids.Audio)
                    {
                        Activate activate;
                        MediaFactory.CreateAudioRendererActivate(out activate);

                        outputNode.Object = activate;
                    }

                    _topology.AddNode(sourceNode);
                    _topology.AddNode(outputNode);
                    sourceNode.ConnectOutput(0, outputNode, 0);

                    sourceNode.Dispose();
                    outputNode.Dispose();
                }

                desc.Dispose();
            }

            presDesc.Dispose();
            mediaSource.Dispose();
        }
Exemple #4
0
        /// <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++)
                {
                    RawBool          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);
        }
Exemple #5
0
        internal Topology GetTopology()
        {
            if (_topology == null)
            {
                MediaManagerState.CheckStartup();

                MediaFactory.CreateTopology(out _topology);

                SharpDX.MediaFoundation.MediaSource mediaSource;
                {
                    SourceResolver resolver;
                    MediaFactory.CreateSourceResolver(out resolver);

                    ObjectType otype;
                    ComObject  source;
                    resolver.CreateObjectFromURL(FilePath, (int)SourceResolverFlags.MediaSource, null, out otype,
                                                 out source);
                    mediaSource = source.QueryInterface <SharpDX.MediaFoundation.MediaSource>();
                    resolver.Dispose();
                    source.Dispose();
                }

                PresentationDescriptor presDesc;
                mediaSource.CreatePresentationDescriptor(out presDesc);

                for (var i = 0; i < presDesc.StreamDescriptorCount; i++)
                {
                    Bool             selected;
                    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.Audio)
                        {
                            throw new NotSupportedException("The song contains video data!");
                        }

                        Activate activate;
                        MediaFactory.CreateAudioRendererActivate(out activate);
                        outputNode.Object = activate;

                        _topology.AddNode(sourceNode);
                        _topology.AddNode(outputNode);
                        sourceNode.ConnectOutput(0, outputNode, 0);

                        sourceNode.Dispose();
                        outputNode.Dispose();
                    }

                    desc.Dispose();
                }

                presDesc.Dispose();
                mediaSource.Dispose();
            }

            return(_topology);
        }
        public override void PlayFile(string filename)
        {
            //Load the file
            MediaSource mediaSource;

            {
                var        resolver = new SourceResolver();
                ObjectType otype;
                var        source = new ComObject(resolver.CreateObjectFromURL(filename, SourceResolverFlags.MediaSource, null, out otype));
                try
                {
                    // Sometimes throws HRESULT: [0x80004002], Module: [General], ApiCode: [E_NOINTERFACE/No such interface supported], Message: No such interface supported. Bug?
                    mediaSource = source.QueryInterface <MediaSource>();
                }
                catch (SharpDXException)
                {
                    mediaSource = null;
                    FLLog.Error("VideoPlayerWMF", "QueryInterface failed on Media Foundation");
                }
                resolver.Dispose();
                source.Dispose();
            }
            if (mediaSource is null)
            {
                return;
            }

            PresentationDescriptor presDesc;

            mediaSource.CreatePresentationDescriptor(out presDesc);

            for (int i = 0; i < presDesc.StreamDescriptorCount; i++)
            {
                SharpDX.Mathematics.Interop.RawBool selected;
                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;

                        videoSampler = new MFSamples();
                        //retrieve size of video
                        long sz = desc.MediaTypeHandler.CurrentMediaType.Get <long>(new Guid("{1652c33d-d6b2-4012-b834-72030849a37d}"));
                        int  height = (int)(sz & uint.MaxValue), width = (int)(sz >> 32);
                        _texture = new Texture2D(width, height, false, SurfaceFormat.Color);
                        mt       = new MediaType();

                        mt.Set(MediaTypeAttributeKeys.MajorType, MediaTypeGuids.Video);

                        // Specify that we want the data to come in as RGB32.
                        mt.Set(MediaTypeAttributeKeys.Subtype, new Guid("00000016-0000-0010-8000-00AA00389B71"));
                        GetMethods();
                        MFCreateSampleGrabberSinkActivate(mt, videoSampler, out activate);
                        outputNode.Object = activate;
                    }

                    if (majorType == MediaTypeGuids.Audio)
                    {
                        Activate activate;
                        MediaFactory.CreateAudioRendererActivate(out activate);

                        outputNode.Object = activate;
                    }

                    topology.AddNode(sourceNode);
                    topology.AddNode(outputNode);
                    sourceNode.ConnectOutput(0, outputNode, 0);

                    sourceNode.Dispose();
                    outputNode.Dispose();
                }
                desc.Dispose();
            }

            presDesc.Dispose();
            mediaSource.Dispose();
            //Play the file
            cb = new MFCallback(this, session);
            session.BeginGetEvent(cb, null);
            session.SetTopology(SessionSetTopologyFlags.Immediate, topology);
            // Get the clock
            clock = session.Clock.QueryInterface <PresentationClock>();

            // Start playing.
            Playing = true;
        }
Exemple #7
0
        private void PlatformInitialize()
        {
            if (Topology != null)
            {
                return;
            }

            //MediaManagerState.CheckStartup();

            MediaFactory.CreateTopology(out _topology);

            SharpDX.MediaFoundation.MediaSource mediaSource;
            {
                SourceResolver resolver = new SourceResolver();

                ObjectType otype;
                ComObject  source = resolver.CreateObjectFromURL(FileName, SourceResolverFlags.MediaSource, null, out otype);
                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 Texture2D(Game.Instance.GraphicsDevice, Width, Height, ColorFormat.Bgra8, false);
        }
Exemple #8
0
        /// <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);
        }
        private void PlatformInitialize(string fileName)
        {
            if (_topology != null)
            {
                return;
            }

            MediaManagerState.CheckStartup();

            MediaFactory.CreateTopology(out _topology);

            SharpDX.MediaFoundation.MediaSource mediaSource;
            {
                SourceResolver resolver = new SourceResolver();

                ComObject source = resolver.CreateObjectFromURL(FilePath, SourceResolverFlags.MediaSource);
                mediaSource = source.QueryInterface <SharpDX.MediaFoundation.MediaSource>();
                resolver.Dispose();
                source.Dispose();
            }

            PresentationDescriptor presDesc;

            mediaSource.CreatePresentationDescriptor(out presDesc);

            for (var i = 0; i < presDesc.StreamDescriptorCount; i++)
            {
                SharpDX.Mathematics.Interop.RawBool selected;
                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 typeHandler = desc.MediaTypeHandler;
                    var majorType   = typeHandler.MajorType;
                    if (majorType != MediaTypeGuids.Audio)
                    {
                        throw new NotSupportedException("The song contains video data!");
                    }

                    Activate activate;
                    MediaFactory.CreateAudioRendererActivate(out activate);
                    outputNode.Object = activate;

                    _topology.AddNode(sourceNode);
                    _topology.AddNode(outputNode);
                    sourceNode.ConnectOutput(0, outputNode, 0);

                    sourceNode.Dispose();
                    outputNode.Dispose();
                    typeHandler.Dispose();
                    activate.Dispose();
                }

                desc.Dispose();
            }

            presDesc.Dispose();
            mediaSource.Dispose();
        }
Exemple #10
0
        public void Load(object customSource)
        {
            Close();
            AfterClose();
            if (Hwnd == IntPtr.Zero)
            {
                throw new InvalidOperationException();
            }
            Trace.WriteLine("HwndRenderSession::Load()");

            MediaSource            source = null;
            Topology               topo   = null;
            PresentationDescriptor pdesc  = null;

            try {
                // Create MediaSource(check argument)
                source = ComObject.As <MediaSource>(Marshal.GetIUnknownForObject(customSource)); // GetIUnknownForObject adds reference count
                // Create MediaSession
                MediaFactory.CreateMediaSession(null, out _mediaSession);
                _callback = new MediaSessionCallback(_mediaSession, OnMediaEvent);
                // Create Topology
                MediaFactory.CreateTopology(out topo);

                // Get PresentationDescriptor from MediaSource
                source.CreatePresentationDescriptor(out pdesc);
                // Connect each stream
                for (var i = 0; i < pdesc.StreamDescriptorCount; i++)
                {
                    RawBool isSelected;
                    using (var sdesc = pdesc.GetStreamDescriptorByIndex(i, out isSelected)) {
                        if (!isSelected)
                        {
                            continue;
                        }

                        Activate     renderer = null;
                        TopologyNode srcnode  = null;
                        TopologyNode outnode  = null;
                        try {
                            // Renderer
                            if (sdesc.MediaTypeHandler.MajorType == MediaTypeGuids.Video)
                            {
                                MediaFactory.CreateVideoRendererActivate(Hwnd, out renderer);
                            }
                            else if (sdesc.MediaTypeHandler.MajorType == MediaTypeGuids.Audio)
                            {
                                MediaFactory.CreateAudioRendererActivate(out renderer);
                            }
                            else
                            {
                                // not supported
                                continue;
                            }
                            // Source Node
                            MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out srcnode);
                            srcnode.Set(TopologyNodeAttributeKeys.Source, source);
                            srcnode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, pdesc);
                            srcnode.Set(TopologyNodeAttributeKeys.StreamDescriptor, sdesc);
                            // Output Node
                            MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outnode);
                            outnode.Object = renderer;

                            // Connect
                            topo.AddNode(srcnode);
                            topo.AddNode(outnode);
                            srcnode.ConnectOutput(0, outnode, 0);
                        } finally {
                            srcnode?.Dispose();
                            outnode?.Dispose();
                            renderer?.Dispose();
                        }
                    }
                }
                // Set to session
                _mediaSession.SetTopology(SessionSetTopologyFlags.None, topo);
            } catch {
                Close();
                AfterClose();
                throw;
            } finally {
                pdesc?.Dispose();
                topo?.Dispose();
                source?.Dispose();
            }
        }