public static HResult GetEnableData(this IMFContentEnabler contentEnabler, out byte[] data) { if (contentEnabler == null) { throw new ArgumentNullException("contentEnabler"); } IntPtr dataPtr; int dataLength; HResult hr = contentEnabler.GetEnableData(out dataPtr, out dataLength); if (hr.Succeeded()) { try { data = new byte[dataLength]; Marshal.Copy(dataPtr, data, 0, dataLength); } finally { Marshal.FreeCoTaskMem(dataPtr); } } else { data = null; } return(hr); }
/////////////////////////////////////////////////////////////////////// // 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)); } }
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; }
/////////////////////////////////////////////////////////////////////// // Name: BeginEnableContent // Description: Called by the PMP session to start the enable action. ///////////////////////////////////////////////////////////////////////// public HResult BeginEnableContent( IMFActivate pEnablerActivate, IMFTopology pTopo, IMFAsyncCallback pCallback, object punkState ) { // Make sure we *never* leave this entry point with an exception try { Debug.WriteLine("ContentProtectionManager::BeginEnableContent"); if (m_pEnabler != null) { throw new COMException("A previous call is still pending", (int)HResult.E_FAIL); } HResult hr; // Save so we can create an async result later m_pCallback = pCallback; m_punkState = punkState; // Create the enabler from the IMFActivate pointer. object o; hr = pEnablerActivate.ActivateObject(typeof(IMFContentEnabler).GUID, out o); MFError.ThrowExceptionForHR(hr); m_pEnabler = o as IMFContentEnabler; // Notify the application. The application will call DoEnable from the app thread. m_state = Enabler.Ready; // Reset the state. PostMessage(m_hwnd, WM_APP_CONTENT_ENABLER, IntPtr.Zero, IntPtr.Zero); return(HResult.S_OK); } catch (Exception e) { return((HResult)Marshal.GetHRForException(e)); } }
/////////////////////////////////////////////////////////////////////// // Name: BeginEnableContent // Description: Called by the PMP session to start the enable action. ///////////////////////////////////////////////////////////////////////// public int BeginEnableContent( IMFActivate pEnablerActivate, IMFTopology pTopo, IMFAsyncCallback pCallback, object punkState ) { // Make sure we *never* leave this entry point with an exception try { Debug.WriteLine("ContentProtectionManager::BeginEnableContent"); if (m_pEnabler != null) { throw new COMException("A previous call is still pending", E_Fail); } int hr; // Save so we can create an async result later m_pCallback = pCallback; m_punkState = punkState; // Create the enabler from the IMFActivate pointer. object o; hr = pEnablerActivate.ActivateObject(typeof(IMFContentEnabler).GUID, out o); MFError.ThrowExceptionForHR(hr); m_pEnabler = o as IMFContentEnabler; // Notify the application. The application will call DoEnable from the app thread. m_state = Enabler.Ready; // Reset the state. PostMessage(m_hwnd, WM_APP_CONTENT_ENABLER, IntPtr.Zero, IntPtr.Zero); return S_Ok; } catch (Exception e) { return Marshal.GetHRForException(e); } }
/////////////////////////////////////////////////////////////////////// // 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); } }