Пример #1
0
    ///////////////////////////////////////////////////////////////////////
    //  Name: DoEnable
    //  Description:  Does the enabler action.
    //
    //  flags: If ForceNonSilent, then always use non-silent enable.
    //         Otherwise, use silent enable if possible.
    ////////////////////////////////////////////////////////////////////////

    public void DoEnable(EnablerFlags flags)
    {
        Debug.WriteLine(string.Format("ContentProtectionManager::DoEnable (flags ={0})", flags.ToString()));

        HResult hr;
        bool    bAutomatic = false;
        Guid    guidEnableType;

        try
        {
            // Get the enable type. (Just for logging. We don't use it.)
            hr = m_pEnabler.GetEnableType(out guidEnableType);
            MFError.ThrowExceptionForHR(hr);

            LogEnableType(guidEnableType);

            // Query for the IMFMediaEventGenerator interface so that we can get the
            // enabler events.
            m_pMEG = (IMFMediaEventGenerator)m_pEnabler;

            // Ask for the first event.
            hr = m_pMEG.BeginGetEvent(this, null);
            MFError.ThrowExceptionForHR(hr);

            // Decide whether to use silent or non-silent enabling. If flags is ForceNonSilent,
            // then we use non-silent. Otherwise, we query whether the enabler object supports
            // silent enabling (also called "automatic" enabling).
            if (flags == EnablerFlags.ForceNonSilent)
            {
                Debug.WriteLine(("Forcing non-silent enable."));
                bAutomatic = false;
            }
            else
            {
                hr = m_pEnabler.IsAutomaticSupported(out bAutomatic);
                MFError.ThrowExceptionForHR(hr);
                Debug.WriteLine(string.Format("IsAutomatic: auto = {0}", bAutomatic));
            }

            // Start automatic or non-silent, depending.
            if (bAutomatic)
            {
                m_state = Enabler.SilentInProgress;
                Debug.WriteLine("Content enabler: Automatic is supported");
                hr = m_pEnabler.AutomaticEnable();
                MFError.ThrowExceptionForHR(hr);
            }
            else
            {
                m_state = Enabler.NonSilentInProgress;
                Debug.WriteLine("Content enabler: Using non-silent enabling");
                DoNonSilentEnable();
            }
        }
        catch (Exception e)
        {
            m_hrStatus = (HResult)Marshal.GetHRForException(e);
            throw;
        }
    }
Пример #2
0
    ///////////////////////////////////////////////////////////////////////
    //  Name: EndEnableContent
    //  Description:  Completes the enable action.
    /////////////////////////////////////////////////////////////////////////

    public HResult EndEnableContent(IMFAsyncResult pResult)
    {
        // Make sure we *never* leave this entry point with an exception
        try
        {
            Debug.WriteLine("ContentProtectionManager::EndEnableContent");

            if (pResult == null)
            {
                throw new COMException("NULL IMFAsyncResult", (int)HResult.E_POINTER);
            }

            // Release interfaces, so that we're ready to accept another call
            // to BeginEnableContent.
            SafeRelease(m_pEnabler);
            SafeRelease(m_pMEG);
            SafeRelease(m_punkState);
            SafeRelease(m_pCallback);

            m_pEnabler  = null;
            m_pMEG      = null;
            m_pCallback = null;
            m_punkState = null;

            return(m_hrStatus);
        }
        catch (Exception e)
        {
            return((HResult)Marshal.GetHRForException(e));
        }
    }
Пример #3
0
    public void Dispose()
    {
        Debug.WriteLine("ContentProtectionManager::Dispose");
        SafeRelease(m_pEnabler);
        SafeRelease(m_pMEG);
        SafeRelease(m_pCallback);
        SafeRelease(m_punkState);

        m_pEnabler  = null;
        m_pMEG      = null;
        m_pCallback = null;
        m_punkState = null;
    }
        private void GetInterface()
        {
            IMFSourceResolver pSourceResolver = null;
            MFObjectType ObjectType;
            object pSource = null;

            // Create the source resolver.
            int hr = MFExtern.MFCreateSourceResolver(out pSourceResolver);
            MFError.ThrowExceptionForHR(hr);

            hr = pSourceResolver.CreateObjectFromURL(
                    @"file://c:/sourceforge/mflib/test/media/AspectRatio4x3.wmv",
                    MFResolution.MediaSource,	// Create a source object.
                    null,						// Optional property store.
                    out ObjectType,				// Receives the created object type.
                    out pSource					// Receives a pointer to the media source.
                );
            MFError.ThrowExceptionForHR(hr);

            // Get the IMFMediaSource interface from the media source.
            m_meg = (IMFMediaEventGenerator)pSource;
        }
Пример #5
0
    ///////////////////////////////////////////////////////////////////////
    //  Name: EndEnableContent
    //  Description:  Completes the enable action.
    /////////////////////////////////////////////////////////////////////////
    public int EndEnableContent(IMFAsyncResult pResult)
    {
        // Make sure we *never* leave this entry point with an exception
        try
        {
            Debug.WriteLine("ContentProtectionManager::EndEnableContent");

            if (pResult == null)
            {
                throw new COMException("NULL IMFAsyncResult", E_Pointer);
            }

            // Release interfaces, so that we're ready to accept another call
            // to BeginEnableContent.
            SafeRelease(m_pEnabler);
            SafeRelease(m_pMEG);
            SafeRelease(m_punkState);
            SafeRelease(m_pCallback);

            m_pEnabler = null;
            m_pMEG = null;
            m_pCallback = null;
            m_punkState = null;

            return m_hrStatus;
        }
        catch (Exception e)
        {
            return Marshal.GetHRForException(e);
        }
    }
Пример #6
0
    ///////////////////////////////////////////////////////////////////////
    //  Name: DoEnable
    //  Description:  Does the enabler action.
    //
    //  flags: If ForceNonSilent, then always use non-silent enable.
    //         Otherwise, use silent enable if possible.
    ////////////////////////////////////////////////////////////////////////
    public void DoEnable(EnablerFlags flags)
    {
        Debug.WriteLine(string.Format("ContentProtectionManager::DoEnable (flags ={0})", flags.ToString()));

        int hr;
        bool bAutomatic = false;
        Guid guidEnableType;

        try
        {
            // Get the enable type. (Just for logging. We don't use it.)
            hr = m_pEnabler.GetEnableType(out guidEnableType);
            MFError.ThrowExceptionForHR(hr);

            LogEnableType(guidEnableType);

            // Query for the IMFMediaEventGenerator interface so that we can get the
            // enabler events.
            m_pMEG = (IMFMediaEventGenerator)m_pEnabler;

            // Ask for the first event.
            hr = m_pMEG.BeginGetEvent(this, null);
            MFError.ThrowExceptionForHR(hr);

            // Decide whether to use silent or non-silent enabling. If flags is ForceNonSilent,
            // then we use non-silent. Otherwise, we query whether the enabler object supports
            // silent enabling (also called "automatic" enabling).
            if (flags == EnablerFlags.ForceNonSilent)
            {
                Debug.WriteLine(("Forcing non-silent enable."));
                bAutomatic = false;
            }
            else
            {
                hr = m_pEnabler.IsAutomaticSupported(out bAutomatic);
                MFError.ThrowExceptionForHR(hr);
                Debug.WriteLine(string.Format("IsAutomatic: auto = {0}", bAutomatic));
            }

            // Start automatic or non-silent, depending.
            if (bAutomatic)
            {
                m_state = Enabler.SilentInProgress;
                Debug.WriteLine("Content enabler: Automatic is supported");
                hr = m_pEnabler.AutomaticEnable();
                MFError.ThrowExceptionForHR(hr);
            }
            else
            {
                m_state = Enabler.NonSilentInProgress;
                Debug.WriteLine("Content enabler: Using non-silent enabling");
                DoNonSilentEnable();
            }
        }
        catch (Exception e)
        {
            m_hrStatus = Marshal.GetHRForException(e);
            throw;
        }
    }
Пример #7
0
    public void Dispose()
    {
        Debug.WriteLine("ContentProtectionManager::Dispose");
        SafeRelease(m_pEnabler);
        SafeRelease(m_pMEG);
        SafeRelease(m_pCallback);
        SafeRelease(m_punkState);

        m_pEnabler = null;
        m_pMEG = null;
        m_pCallback = null;
        m_punkState = null;
    }