Example #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;
        }
    }
Example #2
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;
        }
    }
Example #3
0
    ///////////////////////////////////////////////////////////////////////
    //  Name: Invoke
    //  Description:  Callback for asynchronous BeginGetEvent method.
    //
    //  pAsyncResult: Pointer to the result.
    /////////////////////////////////////////////////////////////////////////

    HResult IMFAsyncCallback.Invoke(IMFAsyncResult pAsyncResult)
    {
        // Make sure we *never* leave this entry point with an exception
        try
        {
            HResult        hr;
            IMFMediaEvent  pEvent;
            MediaEventType meType       = MediaEventType.MEUnknown; // Event type
            PropVariant    varEventData = new PropVariant();        // Event data

            // Get the event from the event queue.
            hr = m_pMEG.EndGetEvent(pAsyncResult, out pEvent);
            MFError.ThrowExceptionForHR(hr);

            // Get the event type.
            hr = pEvent.GetType(out meType);
            MFError.ThrowExceptionForHR(hr);

            // Get the event status. If the operation that triggered the event did
            // not succeed, the status is a failure code.
            hr = pEvent.GetStatus(out m_hrStatus);
            MFError.ThrowExceptionForHR(hr);

            if ((int)m_hrStatus == 862022) // NS_S_DRM_MONITOR_CANCELLED
            {
                m_hrStatus = HResult.MF_E_OPERATION_CANCELLED;
                m_state    = Enabler.Complete;
            }

            // Get the event data.
            hr = pEvent.GetValue(varEventData);
            MFError.ThrowExceptionForHR(hr);

            // For the MEEnablerCompleted action, notify the application.
            // Otherwise, request another event.
            Debug.WriteLine(string.Format("Content enabler event: {0}", meType.ToString()));

            if (meType == MediaEventType.MEEnablerCompleted)
            {
                PostMessage(m_hwnd, WM_APP_CONTENT_ENABLER, IntPtr.Zero, IntPtr.Zero);
            }
            else
            {
                if (meType == MediaEventType.MEEnablerProgress)
                {
                    if (varEventData.GetVariantType() == PropVariant.VariantType.String)
                    {
                        Debug.WriteLine(string.Format("Progress: {0}", varEventData.GetString()));
                    }
                }
                hr = m_pMEG.BeginGetEvent(this, null);
                MFError.ThrowExceptionForHR(hr);
            }

            // Clean up.
            varEventData.Clear();
            SafeRelease(pEvent);

            return(HResult.S_OK);
        }
        catch (Exception e)
        {
            return((HResult)Marshal.GetHRForException(e));
        }
    }