Beispiel #1
0
        static IMFMetadata GetMetadata(IMFMediaSource mediaSource)
        {
            HResult hr;

            // Get IMFPresentationDescriptor.
            IMFPresentationDescriptor presentationDescriptor;

            hr = mediaSource.CreatePresentationDescriptor(out presentationDescriptor);
            MFError.ThrowExceptionForHR(hr);

            // Get IMFMetadataProvider.
            object provider;

            hr = MFExtern.MFGetService(mediaSource, MFServices.MF_METADATA_PROVIDER_SERVICE, typeof(IMFMetadataProvider).GUID, out provider);
            MFError.ThrowExceptionForHR(hr);
            IMFMetadataProvider metadataProvider = (IMFMetadataProvider)provider;

            // Get IMFMetadata.
            IMFMetadata metadata;

            hr = metadataProvider.GetMFMetadata(presentationDescriptor, 0, 0, out metadata);
            MFError.ThrowExceptionForHR(hr);
            COMBase.SafeRelease(presentationDescriptor);
            presentationDescriptor = null;
            COMBase.SafeRelease(metadataProvider);
            metadataProvider = null;

            return(metadata);
        }
Beispiel #2
0
    protected void CreateTopologyFromSource(out IMFTopology ppTopology)
    {
        TRACE("CPlayer::CreateTopologyFromSource");

        Debug.Assert(m_pSession != null);
        Debug.Assert(m_pSource != null);

        IMFTopology pTopology = null;
        IMFPresentationDescriptor pSourcePD = null;
        int     cSourceStreams = 0;
        HResult hr;

        try
        {
            // Create a new topology.
            hr = MFExtern.MFCreateTopology(out pTopology);
            MFError.ThrowExceptionForHR(hr);

            // Create the presentation descriptor for the media source.
            hr = m_pSource.CreatePresentationDescriptor(out pSourcePD);
            MFError.ThrowExceptionForHR(hr);

            {
                // See if there is metadata.  If anything fails,
                // just leave m_pMetadata as null.
                object o;
                hr = MFExtern.MFGetService(
                    m_pSource,
                    MFServices.MF_METADATA_PROVIDER_SERVICE,
                    typeof(IMFMetadataProvider).GUID,
                    out o
                    );

                if (Succeeded(hr))
                {
                    IMFMetadataProvider pMetaProvider = o as IMFMetadataProvider;
                    hr = pMetaProvider.GetMFMetadata(
                        pSourcePD,
                        0,      // Stream id 0 == presentation-level metadata.
                        0,      // Reserved
                        out m_pMetadata);
                }
            }

            // Get the number of streams in the media source.
            hr = pSourcePD.GetStreamDescriptorCount(out cSourceStreams);
            MFError.ThrowExceptionForHR(hr);

            TRACE(string.Format("Stream count: {0}", cSourceStreams));

            // For each stream, create the topology nodes and add them to the topology.
            for (int i = 0; i < cSourceStreams; i++)
            {
                AddBranchToPartialTopology(pTopology, m_hwndVideo, m_pSource, pSourcePD, i);
            }

            // Return the IMFTopology pointer to the caller.
            ppTopology = pTopology;
        }
        catch
        {
            // If we failed, release the topology
            SafeRelease(pTopology);
            throw;
        }
        finally
        {
            SafeRelease(pSourcePD);
        }
    }