private void PlatformInitialize()
        {
            // The GUID is specified in a GuidAttribute attached to the class
            AudioStreamVolumeGuid = Guid.Parse(
                ((GuidAttribute)typeof(AudioStreamVolume).GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value);

            MediaManagerState.CheckStartup();
            MediaFactory.CreateMediaSession(null, out _session);
        }
Пример #2
0
        private void PlatformInitialize()
        {
            if (Topology != null)
            {
                return;
            }

            MediaManagerState.CheckStartup();

            MediaFactory.CreateTopology(out _topology);
            MediaSource mediaSource;

            {
                using (var resolver = new SourceResolver())
                    using (var source = (ComObject)resolver.CreateObjectFromURL(
                               FileName, SourceResolverFlags.MediaSource, null, out _))
                    {
                        mediaSource = source.QueryInterface <MediaSource>();
                    }
            }

            mediaSource.CreatePresentationDescriptor(out PresentationDescriptor presDesc);

            for (int i = 0; i < presDesc.StreamDescriptorCount; i++)
            {
                presDesc.GetStreamDescriptorByIndex(
                    i, out SharpDX.Mathematics.Interop.RawBool selected, out StreamDescriptor desc);

                if (selected)
                {
                    MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out TopologyNode sourceNode);

                    sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource);
                    sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc);
                    sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc);

                    MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out TopologyNode outputNode);

                    var majorType = desc.MediaTypeHandler.MajorType;
                    if (majorType == MediaTypeGuids.Video)
                    {
                        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 activate);
                        outputNode.Object = activate;
                    }

                    if (majorType == MediaTypeGuids.Audio)
                    {
                        MediaFactory.CreateAudioRendererActivate(out Activate 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();
        }
Пример #3
0
        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();
            }

            mediaSource.CreatePresentationDescriptor(out PresentationDescriptor presDesc);

            for (var i = 0; i < presDesc.StreamDescriptorCount; i++)
            {
                presDesc.GetStreamDescriptorByIndex(i, out SharpDX.Mathematics.Interop.RawBool selected, out StreamDescriptor desc);

                if (selected)
                {
                    MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out TopologyNode sourceNode);

                    sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource);
                    sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc);
                    sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc);

                    MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out TopologyNode outputNode);

                    var typeHandler = desc.MediaTypeHandler;
                    var majorType   = typeHandler.MajorType;
                    if (majorType != MediaTypeGuids.Audio)
                    {
                        throw new NotSupportedException("The song contains video data!");
                    }

                    MediaFactory.CreateAudioRendererActivate(out Activate 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();
        }