Example #1
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));
        }
    }
            public int Invoke(IMFAsyncResult asyncResult)
            {
                IMFMediaEvent mediaEvent = null;

                this.mediaSession.EndGetEvent(asyncResult, out mediaEvent);

                // Get the session event type
                uint type = Consts.MESessionUnknown;

                mediaEvent.GetType(out type);

                // Get the session event HRESULT
                int status = 0;

                mediaEvent.GetStatus(out status);

                // Fire the C# event
                if (this.MediaEvent != null)
                {
                    this.MediaEvent(type, status);
                }

                // Get the next session event
                this.mediaSession.BeginGetEvent(this, null);

                return(0);
            }
Example #3
0
        public int Invoke(IMFAsyncResult pAsyncResult)
        {
            Debug.WriteLine("Here");
            m_Count++;

            return 0;
        }
Example #4
0
    public HResult EndGetEvent(IMFAsyncResult pResult,
                               out IMFMediaEvent ppEvent)
    {
        HResult hr;

        hr = m_events.EndGetEvent(pResult, out ppEvent);

        return(hr);
    }
Example #5
0
        public int Invoke(IMFAsyncResult pAsyncResult)
        {
            IMFByteStream bs;
             	        int hr = MFExtern.MFEndCreateFile(pAsyncResult, out bs);
            MFError.ThrowExceptionForHR(hr);
            m_re.Set();

            return 0;
        }
        public int Invoke(IMFAsyncResult pAsyncResult)
        {
            IMFMediaEvent pEvent;
            int hr = m_meg.EndGetEvent(pAsyncResult, out pEvent);
            MFError.ThrowExceptionForHR(hr);
            m_are.Set();

            return S_Ok;
        }
Example #7
0
        public HResult EndGetEvent(IMFAsyncResult pResult, out IMFMediaEvent ppEvent)
        {
            HResult hr = HResult.S_OK;

            ppEvent = null;
            hr      = CheckShutdown();
            if (MFError.Succeeded(hr))
            {
                hr = _spEventQueue.EndGetEvent(pResult, out ppEvent);
            }
            return(hr);
        }
Example #8
0
        public int Invoke(IMFAsyncResult pAsyncResult)
        {
            int i;
            object o;
            IntPtr ip = Marshal.AllocCoTaskMem(8);

            int hr = pAsyncResult.GetState(out o);
            MFError.ThrowExceptionForHR(hr);
            Debug.Assert(o == this);

            ip = pAsyncResult.GetStateNoAddRef();
            o = Marshal.GetObjectForIUnknown(ip);
            Debug.Assert(o == this);

            hr = pAsyncResult.SetStatus(-1);
            MFError.ThrowExceptionForHR(hr);
            hr = pAsyncResult.GetStatus();
            Debug.Assert(hr == -1);

            try
            {
                // Since the IMFAsyncResult was created with no
                hr = pAsyncResult.GetObject(out o);
                Debug.Assert(hr == E_Pointer);
            }
            catch (Exception e)
            {
                Debug.Assert(e is NullReferenceException);
            }

            if (!m_write)
            {
                hr = m_bs.EndRead(pAsyncResult, out i);
                MFError.ThrowExceptionForHR(hr);

                Debug.Assert(i == 32);
            }
            else
            {
                hr = m_bs.EndWrite(pAsyncResult, out i);
                MFError.ThrowExceptionForHR(hr);

                Debug.Assert(i == 32);
            }

            m_mre.Set();

            return 0;
        }
Example #9
0
        public HResult BeginCreateObject(
            IMFByteStream pByteStream,
            string pwszURL,
            MFResolution dwFlags,
            IPropertyStore pProps,             // Can be NULL.
            out object ppIUnknownCancelCookie, // Can be NULL.
            IMFAsyncCallback pCallback,
            object punkState                   // Can be NULL
            )
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                HResult hr;
                m_Log.WriteLine("BeginCreateObject");

                ppIUnknownCancelCookie = null; // We don't return a cancellation cookie.

                if ((pByteStream == null) || (pwszURL == null) || (pCallback == null))
                {
                    throw new COMException("bad stream, url, or callback", (int)HResult.E_INVALIDARG);
                }

                IMFAsyncResult pResult = null;

                WavSource pSource = new WavSource();

                pSource.Open(pByteStream);

                hr = MFExtern.MFCreateAsyncResult(pSource as IMFMediaSource, pCallback, punkState, out pResult);
                MFError.ThrowExceptionForHR(hr);

                hr = MFExtern.MFInvokeCallback(pResult);
                MFError.ThrowExceptionForHR(hr);

                if (pResult != null)
                {
                    Marshal.ReleaseComObject(pResult);
                }
                return(HResult.S_OK);
            }
            catch (Exception e)
            {
                ppIUnknownCancelCookie = null;
                return((HResult)Marshal.GetHRForException(e));
            }
        }
        public int Invoke(IMFAsyncResult pAsyncResult)
        {
            int hr;
            if (m_IsURL)
            {
                object o;
                MFObjectType ot;

                try
                {
                    hr = m_sr.EndCreateObjectFromURL(pAsyncResult, out ot, out o);
                    MFError.ThrowExceptionForHR(hr);
                    Debug.WriteLine(ot);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                finally
                {
                    m_mre.Set();
                }
            }
            else
            {
                object o;
                MFObjectType ot;

                try
                {
                    hr = m_sr.EndCreateObjectFromByteStream(pAsyncResult, out ot, out o);
                    MFError.ThrowExceptionForHR(hr);
                    Debug.WriteLine(ot);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                finally
                {
                    m_mre.Set();
                }
            }
            return 0;
        }
Example #11
0
        public HResult Invoke(IMFAsyncResult pAsyncResult)
        {
            HResult hr;

            if ((hr = pAsyncResult.GetState(out object ppvState)).Succeeded())
            {
                // (A) State がある(E_POINTERエラーじゃない)場合

                if (this.ID_RegistarTopologyWorkQueueWithMMCSS == ppvState)
                {
                    this.OnEndRegistarTopologyWorkQueueWithMMCSS(pAsyncResult);
                    return(HResult.S_OK);
                }
                else
                {
                    return(HResult.E_INVALIDARG);
                }
            }
Example #12
0
    public HResult Invoke(IMFAsyncResult pAsyncResult)
    {
        // IMFByteStream::BeginRead end up here.

        object         pState;
        object         pUnk;
        IMFAsyncResult pCallerResult;
        MFError        hrthrowonerror;

        ReadParams rp;

        // Get the asynchronous result object for the application callback.
        hrthrowonerror = pAsyncResult.GetState(out pState);

        pCallerResult = (IMFAsyncResult)pState;

        // Get the object that holds the state information for the
        // asynchronous method.
        hrthrowonerror = pCallerResult.GetObject(out pUnk);

        rp = (ReadParams)pUnk;

        HResult hr;

        // Do the work.
        try
        {
            // DoRead might block
            DoRead(rp.pb, rp.cb);
            hr = HResult.S_OK;
        }
        catch
        {
            Dispose();
            hr = HResult.E_ABORT;
        }

        pCallerResult.SetStatus(hr);
        hr = MFExtern.MFInvokeCallback(pCallerResult);

        return(hr);
    }
Example #13
0
    public HResult EndCreateObject(IMFAsyncResult pResult,
                                   out MFObjectType pObjectType,
                                   out object ppObject)
    {
        pObjectType = MFObjectType.ByteStream;

        HResult hr = pResult.GetObject(out ppObject);

        if (MFError.Succeeded(hr))
        {
            IcyScheme icy = (IcyScheme)ppObject;

            // Wait for the HttpWebRequest to finish connecting.  This
            // includes sending the request, and processing the response
            // headers and caching some data (see m_FirstBlock).
            hr = icy.WaitForConnect();
        }

        return(hr);
    }
Example #14
0
        public HResult EndCreateObject(
            IMFAsyncResult pResult,
            out MFObjectType pObjectType,
            out object ppObject
            )
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                HResult hr;

                pObjectType = MFObjectType.Invalid;
                ppObject    = null;

                m_Log.WriteLine("EndCreateObject");

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

                hr = pResult.GetObject(out ppObject);
                MFError.ThrowExceptionForHR(hr);

                // Minimal sanity check - is it really a media source?
                IMFMediaSource pSource = (IMFMediaSource)ppObject;

                pObjectType = MFObjectType.MediaSource;

                // unneeded SAFE_RELEASE(pSource);
                // unneeded SAFE_RELEASE(ppObject);
                return(HResult.S_OK);
            }
            catch (Exception e)
            {
                ppObject    = null;
                pObjectType = MFObjectType.Invalid;
                return((HResult)Marshal.GetHRForException(e));
            }
        }
Example #15
0
    public HResult EndRead(IMFAsyncResult pResult, out int pcbRead)
    {
        // In theory, pcbRead might be less than what was requested. However
        // that seems to drive our caller nuts, so we only do that when
        // m_Position < 0.
        HResult hr;
        object  o;

        hr = pResult.GetObject(out o);

        if (MFError.Succeeded(hr))
        {
            ReadParams rp = (ReadParams)o;
            pcbRead = rp.cb;
        }
        else
        {
            pcbRead = 0;
        }

        return(hr);
    }
            public int EndWrite(IMFAsyncResult pResult, out int pcbWritten)
            {
                pcbWritten = 0;

                do
                {
                    if (pResult == null)
                    {
                        break;
                    }

                    var lstatus = pResult.GetStatus();

                    if (lstatus != 0)
                    {
                        break;
                    }

                    object lIUnknow;

                    var lresult = pResult.GetObject(out lIUnknow);

                    if (lresult != 0)
                    {
                        break;
                    }

                    var lAsyncWriteData = lIUnknow as AsyncWriteData;

                    if (lAsyncWriteData == null)
                    {
                        break;
                    }

                    pcbWritten = lAsyncWriteData.cb;
                } while (false);

                return(0);
            }
Example #17
0
 public static extern void MFCreateAsyncResult(
     [MarshalAs(UnmanagedType.IUnknown)] object punkObject,
     IMFAsyncCallback pCallback,
     [MarshalAs(UnmanagedType.IUnknown)] object punkState,
     out IMFAsyncResult ppAsyncResult
     );
Example #18
0
        public void Dispose()
        {
            TRACE("CWavStream::Dispose");

            SafeRelease(m_pEventQueue);
            SafeRelease(m_pByteStream);
            SafeRelease(m_pCurrentType);
            SafeRelease(m_pFinalizeResult);

            m_pEventQueue = null;
            m_pByteStream = null;
            m_pCurrentType = null;
            m_pFinalizeResult = null;

            //m_pSink.Dispose();  // break deadly embrace
            m_pSink = null;
            GC.SuppressFinalize(this);
        }
Example #19
0
        public int Invoke(IMFAsyncResult pAsyncResult)
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                try
                {
                    OnSampleFree(pAsyncResult);
                }
                finally
                {
                    SafeRelease(pAsyncResult);
                }

                return S_Ok;
            }
            catch (Exception e)
            {
                return Marshal.GetHRForException(e);
            }
        }
 HResult IMFAsyncCallback.Invoke([In, MarshalAs(UnmanagedType.Interface)] IMFAsyncResult pAsyncResult)
 {
     /// ...or public.
 }
Example #21
0
        void IMFAsyncCallback.Invoke(IMFAsyncResult pResult)
        {
            IMFMediaEvent  pEvent     = null;
            MediaEventType meType     = MediaEventType.MEUnknown; // Event type
            int            hrStatus   = 0;                        // Event status
            MFTopoStatus   TopoStatus = MFTopoStatus.Invalid;     // Used with MESessionTopologyStatus event.

            try
            {
                // Get the event from the event queue.
                m_pSession.EndGetEvent(pResult, out pEvent);

                // Get the event type.
                pEvent.GetType(out meType);

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

                TRACE(string.Format("Media event: " + meType.ToString()));

                // Check if the async operation succeeded.
                if (Succeeded(hrStatus))
                {
                    // Switch on the event type. Update the internal state of the CPlayer as needed.
                    switch (meType)
                    {
                    case MediaEventType.MESessionTopologyStatus:
                        // Get the status code.
                        int i;
                        pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_TOPOLOGY_STATUS, out i);
                        TopoStatus = (MFTopoStatus)i;
                        switch (TopoStatus)
                        {
                        case MFTopoStatus.Ready:
                            OnTopologyReady(pEvent);
                            break;

                        default:
                            // Nothing to do.
                            break;
                        }
                        break;

                    case MediaEventType.MESessionStarted:
                        OnSessionStarted(pEvent);
                        break;

                    case MediaEventType.MESessionPaused:
                        OnSessionPaused(pEvent);
                        break;

                    case MediaEventType.MESessionClosed:
                        OnSessionClosed(pEvent);
                        break;

                    case MediaEventType.MEEndOfPresentation:

                        OnPresentationEnded(pEvent);
                        break;
                    }
                }
                else
                {
                    // The async operation failed. Notify the application
                    NotifyError(hrStatus);
                }
            }
            finally
            {
                // Request another event.
                if (meType != MediaEventType.MESessionClosed)
                {
                    m_pSession.BeginGetEvent(this, null);
                }

                SafeRelease(pEvent);
            }
        }
Example #22
0
        //-------------------------------------------------------------------
        // Name: EndFinalize
        // Description: Completes the asynchronous finalize operation.
        //-------------------------------------------------------------------
        public int EndFinalize(IMFAsyncResult pResult)
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                TRACE("CWavSink::EndFinalize");

                // Return the status code from the async result.
                int hr = pResult.GetStatus();
                if (hr < 0)
                {
                    throw new COMException("Failed status code in EndFinalize", hr);
                }
                return S_Ok;
            }
            catch (Exception e)
            {
                return Marshal.GetHRForException(e);
            }
        }
Example #23
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));
        }
    }
Example #24
0
        //-------------------------------------------------------------------
        // Name: Shutdown
        // Description: Shuts down the stream sink.
        //-------------------------------------------------------------------
        public void Shutdown()
        {
            int hr;
            Debug.Assert(!m_IsShutdown);
            GC.SuppressFinalize(this);

            if (m_pEventQueue != null)
            {
                hr = m_pEventQueue.Shutdown();
                MFError.ThrowExceptionForHR(hr);
            }

            hr = MFExtern.MFUnlockWorkQueue(m_WorkQueueId);
            MFError.ThrowExceptionForHR(hr);

            m_SampleQueue.Clear();

            SafeRelease(m_pSink);
            SafeRelease(m_pEventQueue);
            SafeRelease(m_pByteStream);
            SafeRelease(m_pCurrentType);
            SafeRelease(m_pFinalizeResult);

            m_pSink = null;
            m_pEventQueue = null;
            m_pByteStream = null;
            m_pCurrentType = null;
            m_pFinalizeResult = null;

            m_IsShutdown = true;
        }
Example #25
0
        void IMFAsyncCallback.Invoke(IMFAsyncResult pResult)
        {
            IMFMediaEvent pEvent = null;
            MediaEventType meType = MediaEventType.MEUnknown;  // Event type
            int hrStatus = 0;           // Event status
            MFTopoStatus TopoStatus = MFTopoStatus.Invalid; // Used with MESessionTopologyStatus event.

            try
            {
                // Get the event from the event queue.
                m_pSession.EndGetEvent(pResult, out pEvent);

                // Get the event type.
                pEvent.GetType(out meType);

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

                TRACE(string.Format("Media event: " + meType.ToString()));

                // Check if the async operation succeeded.
                if (Succeeded(hrStatus))
                {
                    // Switch on the event type. Update the internal state of the CPlayer as needed.
                    switch (meType)
                    {
                        case MediaEventType.MESessionTopologyStatus:
                            // Get the status code.
                            int i;
                            pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_TOPOLOGY_STATUS, out i);
                            TopoStatus = (MFTopoStatus)i;
                            switch (TopoStatus)
                            {
                                case MFTopoStatus.Ready:
                                    OnTopologyReady(pEvent);
                                    break;
                                default:
                                    // Nothing to do.
                                    break;
                            }
                            break;

                        case MediaEventType.MESessionStarted:
                            OnSessionStarted(pEvent);
                            break;

                        case MediaEventType.MESessionPaused:
                            OnSessionPaused(pEvent);
                            break;

                        case MediaEventType.MESessionClosed:
                            OnSessionClosed(pEvent);
                            break;

                        case MediaEventType.MEEndOfPresentation:

                            OnPresentationEnded(pEvent);
                            break;
                    }
                }
                else
                {
                    // The async operation failed. Notify the application
                    NotifyError(hrStatus);
                }
            }
            finally
            {
                // Request another event.
                if (meType != MediaEventType.MESessionClosed)
                {
                    m_pSession.BeginGetEvent(this, null);
                }

                SafeRelease(pEvent);
            }
        }
Example #26
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Part of the IMFAsyncCallback interface. This is called when an
        /// asynchronous operation is completed.
        /// </summary>
        /// <param name="pResult">Pointer to the IMFAsyncResult interface. </param>
        /// <returns>S_OK for success, others for fail</returns>
        /// <history>
        ///    01 Nov 18  Cynic - Originally Written
        /// </history>
        HResult IMFAsyncCallback.Invoke(IMFAsyncResult pResult)
        {
            HResult        hr;
            IMFMediaEvent  eventObj = null;
            MediaEventType meType   = MediaEventType.MEUnknown; // Event type
            HResult        hrStatus = 0;                        // Event status

            lock (this)
            {
                try
                {
                    if (MediaSession == null)
                    {
                        return(HResult.S_OK);
                    }

                    // Complete the asynchronous request this is tied to the previous BeginGetEvent call
                    // and MUST be done. The output here is a pointer to the IMFMediaEvent interface describing
                    // this event. Note we MUST release this interface
                    hr = MediaSession.EndGetEvent(pResult, out eventObj);
                    if (hr != HResult.S_OK)
                    {
                        throw new Exception("IMFAsyncCallback.Invoke call to MediaSession.EndGetEvent failed. Err=" + hr.ToString());
                    }
                    if (eventObj == null)
                    {
                        throw new Exception("IMFAsyncCallback.Invoke call to MediaSession.EndGetEvent failed. eventObj == null");
                    }

                    // Get the event type. The event type indicates what happened to trigger the event.
                    // It also defines the meaning of the event value.
                    hr = eventObj.GetType(out meType);
                    if (hr != HResult.S_OK)
                    {
                        throw new Exception("IMFAsyncCallback.Invoke call to IMFMediaEvent.GetType failed. Err=" + hr.ToString());
                    }

                    // Get the event status. If the operation that generated the event was successful,
                    // the value is a success code. A failure code means that an error condition triggered the event.
                    hr = eventObj.GetStatus(out hrStatus);
                    if (hr != HResult.S_OK)
                    {
                        throw new Exception("IMFAsyncCallback.Invoke call to IMFMediaEvent.GetStatus failed. Err=" + hr.ToString());
                    }
                    // Check if we are being told that the the async event succeeded.
                    if (hrStatus != HResult.S_OK)
                    {
                        // The async operation failed. Notify the application
                        if (MediaSessionAsyncCallBackError != null)
                        {
                            MediaSessionAsyncCallBackError(this, "Error Code =" + hrStatus.ToString(), null);
                        }
                    }
                    else
                    {
                        // we are being told the operation succeeded and therefore the event contents are meaningful.
                        // Switch on the event type.
                        switch (meType)
                        {
                        // we let the app handle all of these. There is not really much we can do here
                        default:
                            MediaSessionAsyncCallBackEvent(this, eventObj, meType);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // The async operation failed. Notify the application
                    if (MediaSessionAsyncCallBackError != null)
                    {
                        MediaSessionAsyncCallBackError(this, ex.Message, ex);
                    }
                }
                finally
                {
                    // Request another event if we are still operational.
                    if (((meType == MediaEventType.MESessionClosed) || (meType == MediaEventType.MEEndOfPresentation)) == false)
                    {
                        // Begins an asynchronous request for the next event in the queue
                        hr = MediaSession.BeginGetEvent(this, null);
                        if (hr != HResult.S_OK)
                        {
                            throw new Exception("IMFAsyncCallback.Invoke call to MediaSession.BeginGetEvent failed. Err=" + hr.ToString());
                        }
                    }
                    // release the event we just processed
                    if (eventObj != null)
                    {
                        Marshal.ReleaseComObject(eventObj);
                    }
                }
            } // bottom of lock(this)

            return(HResult.S_OK);
        }
Example #27
0
    public HResult Invoke(IMFAsyncResult pResult)
    {
        object         pUnkObject;
        IMFSample      pSample     = null;
        IMFMediaBuffer pBuffer     = null;
        IMFDXGIBuffer  pDXGIBuffer = null;

        // Get the IUnknown out of the IMFAsyncResult if there is one
        HResult hr = pResult.GetObject(out pUnkObject);

        if (Succeeded(hr))
        {
            pSample = pUnkObject as IMFSample;
        }

        if (pSample != null)
        {
            // Based on your implementation, there should only be one
            // buffer attached to one sample, so we can always grab the
            // first buffer. You could add some error checking here to make
            // sure the sample has a buffer count that is 1.
            hr = pSample.GetBufferByIndex(0, out pBuffer);
        }

        if (Succeeded(hr))
        {
            // Query the IMFMediaBuffer to see if it implements IMFDXGIBuffer
            pDXGIBuffer = pBuffer as IMFDXGIBuffer;
        }
        if (pDXGIBuffer != null)
        {
            // Got an IMFDXGIBuffer, so we can extract the internal
            // ID3D11Texture2D and make a new SharpDX.Texture2D wrapper.
            hr = pDXGIBuffer.GetResource(s_IID_ID3D11Texture2D, out pUnkObject);
        }
        if (Succeeded(hr))
        {
            // If we got here, pUnkObject is the native D3D11 Texture2D as
            // a System.Object, but it's unlikely you have an interface
            // definition for ID3D11Texture2D handy, so we can't just cast
            // the object to the proper interface.

            // Happily, SharpDX supports wrapping System.Object within
            // SharpDX.ComObject which makes things pretty easy.
            SharpDX.ComObject comWrapper = new SharpDX.ComObject(pUnkObject);
            // If this doesn't work, or you're using something like SlimDX
            // which doesn't support object wrapping the same way, the below
            // code is an alternative way.

            /*
             * IntPtr pD3DTexture2D = Marshal.GetIUnknownForObject(pUnkObject);
             * // Create your wrapper object here, like this for SharpDX
             * SharpDX.ComObject comWrapper = new SharpDX.ComObject(pD3DTexture2D);
             * // or like this for SlimDX
             * SlimDX.Direct3D11.Texture2D.FromPointer(pD3DTexture2D);
             * Marshal.Release(pD3DTexture2D);
             */
            // You might need to query comWrapper for a SharpDX.DXGI.Resource
            // first, then query that for the SharpDX.Direct3D11.Texture2D.
            SharpDX.Direct3D11.Texture2D texture = comWrapper.QueryInterface <SharpDX.Direct3D11.Texture2D>();
            if (texture != null)
            {
                // Now you can add "texture" back to the allocator's free list
                ReturnFreeTexture(texture);
            }
        }
    }
Example #28
0
 public static extern void MFInvokeCallback(
     IMFAsyncResult pAsyncResult
     );
Example #29
0
        public HResult Invoke(IMFAsyncResult result)
        {
            IMFMediaEvent  mediaEvent     = null;
            MediaEventType mediaEventType = MediaEventType.MEUnknown;
            bool           getNext        = true;

            try
            {
                _basePlayer.mf_MediaSession.EndGetEvent(result, out mediaEvent);
                mediaEvent.GetType(out mediaEventType);
                mediaEvent.GetStatus(out HResult errorCode);

                if (_basePlayer._playing)
                {
                    if (mediaEventType == MediaEventType.MEError ||
                        (_basePlayer._webcamMode && mediaEventType == MediaEventType.MEVideoCaptureDeviceRemoved) ||
                        (_basePlayer._micMode && mediaEventType == MediaEventType.MECaptureAudioSessionDeviceRemoved))
                    //if (errorCode < 0)
                    {
                        _basePlayer._lastError = errorCode;
                        errorCode = Player.NO_ERROR;
                        getNext   = false;
                    }

                    if (errorCode >= 0)
                    {
                        if (!getNext || mediaEventType == MediaEventType.MESessionEnded)
                        {
                            if (getNext)
                            {
                                _basePlayer._lastError = Player.NO_ERROR;
                                if (!_basePlayer._repeat)
                                {
                                    getNext = false;
                                }
                            }

                            Control control = _basePlayer._display;
                            if (control == null)
                            {
                                FormCollection forms = Application.OpenForms;
                                if (forms != null && forms.Count > 0)
                                {
                                    control = forms[0];
                                }
                            }
                            if (control != null)
                            {
                                control.BeginInvoke(CallEndOfMedia);
                            }
                            else
                            {
                                _basePlayer.AV_EndOfMedia();
                            }
                        }
                    }
                    else
                    {
                        _basePlayer._lastError = errorCode;
                    }
                }
                else
                {
                    _basePlayer._lastError = errorCode;
                }
            }
            finally
            {
                if (getNext && mediaEventType != MediaEventType.MESessionClosed)
                {
                    _basePlayer.mf_MediaSession.BeginGetEvent(this, null);
                }
                if (mediaEvent != null)
                {
                    Marshal.ReleaseComObject(mediaEvent);
                }

                if (_basePlayer.mf_AwaitCallback)
                {
                    _basePlayer.mf_AwaitCallback = false;
                    _basePlayer.WaitForEvent.Set();
                }
                _basePlayer.mf_AwaitDoEvents = false;
            }
            return(0);
        }
 public int EndRead(IMFAsyncResult pResult, out int pcbRead)
 {
     throw new NotImplementedException();
 }
        public int EndCreateObject(
            IMFAsyncResult pResult,
            out MFObjectType pObjectType,
            out object ppObject
        )
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                int hr;

                pObjectType = MFObjectType.Invalid;
                ppObject = null;

                m_Log.WriteLine("EndCreateObject");

                if (pResult == null)
                {
                    throw new COMException("invalid IMFAsyncResult", E_InvalidArgument);
                }

                hr = pResult.GetObject(out ppObject);
                MFError.ThrowExceptionForHR(hr);

                // Minimal sanity check - is it really a media source?
                IMFMediaSource pSource = (IMFMediaSource)ppObject;

                pObjectType = MFObjectType.MediaSource;

                // unneeded SAFE_RELEASE(pSource);
                // unneeded SAFE_RELEASE(ppObject);
                return S_Ok;
            }
            catch (Exception e)
            {
                ppObject = null;
                pObjectType = MFObjectType.Invalid;
                return Marshal.GetHRForException(e);
            }
        }
Example #32
0
        //////////////////////////////////////////////////////////////////////////
        //  Name: CPlayer::Invoke
        //  Description:
        //      Implementation of CAsyncCallback::Invoke.
        //      Callback for asynchronous BeginGetEvent method.
        //  Parameter:
        //      pAsyncResult: Pointer to the result.
        //
        /////////////////////////////////////////////////////////////////////////
        int IMFAsyncCallback.Invoke(IMFAsyncResult pAsyncResult)
        {
            MediaEventType eventType = MediaEventType.MEUnknown;
            IMFMediaEvent pEvent;
            PropVariant eventData = null;
            Exception excpt = null;
            int hr = S_Ok;

            try
            {
                int eventStatus = 0;             // Event status
                eventData = new PropVariant();                  // Event data

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

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

                // Get the event data
                hr = pEvent.GetValue(eventData);
                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 eventStatus);
                MFError.ThrowExceptionForHR(hr);

                // Switch on the event type. Update the internal state of the CPlayer
                // as needed.

                switch (eventType)
                {
                    // Session events
                    case MediaEventType.MESessionStarted:
                        {
                            Debug.WriteLine(string.Format("{0}: MESessionStarted, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            m_State = PlayerState.Playing;
                            PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr((int)m_State));

                            break;
                        }
                    case MediaEventType.MESessionPaused:
                        {
                            Debug.WriteLine(string.Format("{0}: MESessionPaused, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            m_State = PlayerState.Paused;
                            PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr((int)m_State));

                            break;
                        }
                    case MediaEventType.MESessionStopped:
                        {
                            Debug.WriteLine(string.Format("{0}: MESessionStopped, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            m_State = PlayerState.Stopped;
                            PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr((int)m_State));

                            break;
                        }

                    case MediaEventType.MESessionTopologyStatus:
                        {
                            Debug.WriteLine(string.Format("{0}: MESessionTopologyStatus, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            int value = 0;

                            hr = pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_TOPOLOGY_STATUS, out value);
                            MFError.ThrowExceptionForHR(hr);
                            int SegmentID = 0;
                            long ID;

                            //Get information about the new segment
                            IMFTopology pTopology;

                            pTopology = (IMFTopology)eventData.GetIUnknown();

                            try
                            {
                                hr = pTopology.GetTopologyID(out ID);
                                MFError.ThrowExceptionForHR(hr);
                                m_Segments.GetSegmentIDByTopoID(ID, out SegmentID);

                                topostat.iTopologyStatusType = (MFTopoStatus)value;
                                topostat.iSegmentId = SegmentID;

                                switch (topostat.iTopologyStatusType)
                                {
                                    case MFTopoStatus.StartedSource:
                                        m_ActiveSegment = SegmentID;
                                        break;

                                    case MFTopoStatus.Ended:
                                        m_ActiveSegment = -1;
                                        break;
                                }

                                GCHandle gc = GCHandle.Alloc(topostat);

                                PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)MediaEventType.MESessionTopologyStatus), GCHandle.ToIntPtr(gc));
                            }
                            finally
                            {
                                SafeRelease(pTopology);
                            }

                            break;
                        }
                    case MediaEventType.MENewPresentation:
                        {
                            Debug.WriteLine(string.Format("{0}: MENewPresentation, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            IMFPresentationDescriptor pPresentationDescriptor;

                            int SegmentId = 0;

                            pPresentationDescriptor = (IMFPresentationDescriptor)eventData.GetIUnknown();

                            try
                            {
                                //Queue the next segment on the media session
                                QueueNextSegment(pPresentationDescriptor, out SegmentId);
                            }
                            finally
                            {
                                SafeRelease(pPresentationDescriptor);
                            }

                            PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr(SegmentId));

                            break;
                        }

                    case MediaEventType.MEEndOfPresentation:
                        {
                            Debug.WriteLine(string.Format("{0}: MEEndOfPresentation, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            int value = 0;

                            try
                            {
                                hr = pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_SOURCE_TOPOLOGY_CANCELED, out value);
                                MFError.ThrowExceptionForHR(hr);
                            }
                            catch { }

                            PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr(value));

                            break;
                        }

                    case MediaEventType.MEEndOfPresentationSegment:
                        {
                            Debug.WriteLine(string.Format("{0}: MEEndOfPresentationSegment, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            int value = 0;

                            try
                            {
                                hr = pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_SOURCE_TOPOLOGY_CANCELED, out value);
                                MFError.ThrowExceptionForHR(hr);
                            }
                            catch { }

                            PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr(value));

                            break;
                        }

                    case MediaEventType.MESessionNotifyPresentationTime:
                        {
                            Debug.WriteLine(string.Format("{0}: MESessionNotifyPresentationTime, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            HandleNotifyPresentationTime(pEvent);
                            break;
                        }
                    case MediaEventType.MESessionClosed:
                        {
                            Debug.WriteLine(string.Format("{0}: MESessionClosed, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                            m_hCloseEvent.Set();

                            break;
                        }

                    default:
                        Debug.WriteLine(string.Format("{0}: Event", eventType.ToString()));
                        break;
                }

            }
            catch (Exception e)
            {
                excpt = e;
            }
            finally
            {
                if (eventData != null)
                {
                    eventData.Clear();
                }
            }

            // Request another event.
            if (eventType != MediaEventType.MESessionClosed)
            {
                hr = m_pMediaSession.BeginGetEvent(this, null);
                MFError.ThrowExceptionForHR(hr);
            }

            if (excpt == null)
            {
                hr = S_Ok;
            }
            else
            {
                hr = Marshal.GetHRForException(excpt);
            }

            return hr;
        }
Example #33
0
 public static extern void MFPutWorkItemEx(
     int dwQueue,
     IMFAsyncResult pResult);
Example #34
0
        //////////////////////////////////////////////////////////////////////////
        //  Name: CPlayer::Invoke
        //  Description:
        //      Implementation of CAsyncCallback::Invoke.
        //      Callback for asynchronous BeginGetEvent method.
        //  Parameter:
        //      pAsyncResult: Pointer to the result.
        //
        /////////////////////////////////////////////////////////////////////////

        HResult IMFAsyncCallback.Invoke(IMFAsyncResult pAsyncResult)
        {
            MediaEventType eventType = MediaEventType.MEUnknown;
            IMFMediaEvent  pEvent;
            PropVariant    eventData = null;
            Exception      excpt     = null;
            HResult        hr        = HResult.S_OK;

            try
            {
                HResult eventStatus = 0;             // Event status
                eventData = new PropVariant();       // Event data

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

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

                // Get the event data
                hr = pEvent.GetValue(eventData);
                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 eventStatus);
                MFError.ThrowExceptionForHR(hr);

                // Switch on the event type. Update the internal state of the CPlayer
                // as needed.

                switch (eventType)
                {
                // Session events
                case MediaEventType.MESessionStarted:
                {
                    Debug.WriteLine(string.Format("{0}: MESessionStarted, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    m_State = PlayerState.Playing;
                    PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr((int)m_State));

                    break;
                }

                case MediaEventType.MESessionPaused:
                {
                    Debug.WriteLine(string.Format("{0}: MESessionPaused, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    m_State = PlayerState.Paused;
                    PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr((int)m_State));

                    break;
                }

                case MediaEventType.MESessionStopped:
                {
                    Debug.WriteLine(string.Format("{0}: MESessionStopped, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    m_State = PlayerState.Stopped;
                    PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr((int)m_State));

                    break;
                }

                case MediaEventType.MESessionTopologyStatus:
                {
                    Debug.WriteLine(string.Format("{0}: MESessionTopologyStatus, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    int value = 0;

                    hr = pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_TOPOLOGY_STATUS, out value);
                    MFError.ThrowExceptionForHR(hr);
                    int  SegmentID = 0;
                    long ID;

                    //Get information about the new segment
                    IMFTopology pTopology;

                    pTopology = (IMFTopology)eventData.GetIUnknown();

                    try
                    {
                        hr = pTopology.GetTopologyID(out ID);
                        MFError.ThrowExceptionForHR(hr);
                        m_Segments.GetSegmentIDByTopoID(ID, out SegmentID);

                        topostat.iTopologyStatusType = (MFTopoStatus)value;
                        topostat.iSegmentId          = SegmentID;

                        switch (topostat.iTopologyStatusType)
                        {
                        case MFTopoStatus.StartedSource:
                            m_ActiveSegment = SegmentID;
                            break;

                        case MFTopoStatus.Ended:
                            m_ActiveSegment = -1;
                            break;
                        }

                        GCHandle gc = GCHandle.Alloc(topostat);

                        PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)MediaEventType.MESessionTopologyStatus), GCHandle.ToIntPtr(gc));
                    }
                    finally
                    {
                        SafeRelease(pTopology);
                    }

                    break;
                }

                case MediaEventType.MENewPresentation:
                {
                    Debug.WriteLine(string.Format("{0}: MENewPresentation, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    IMFPresentationDescriptor pPresentationDescriptor;

                    int SegmentId = 0;

                    pPresentationDescriptor = (IMFPresentationDescriptor)eventData.GetIUnknown();

                    try
                    {
                        //Queue the next segment on the media session
                        QueueNextSegment(pPresentationDescriptor, out SegmentId);
                    }
                    finally
                    {
                        SafeRelease(pPresentationDescriptor);
                    }

                    PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr(SegmentId));

                    break;
                }

                case MediaEventType.MEEndOfPresentation:
                {
                    Debug.WriteLine(string.Format("{0}: MEEndOfPresentation, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    int value = 0;

                    try
                    {
                        hr = pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_SOURCE_TOPOLOGY_CANCELED, out value);
                        MFError.ThrowExceptionForHR(hr);
                    }
                    catch { }

                    PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr(value));

                    break;
                }

                case MediaEventType.MEEndOfPresentationSegment:
                {
                    Debug.WriteLine(string.Format("{0}: MEEndOfPresentationSegment, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    int value = 0;

                    try
                    {
                        hr = pEvent.GetUINT32(MFAttributesClsid.MF_EVENT_SOURCE_TOPOLOGY_CANCELED, out value);
                        MFError.ThrowExceptionForHR(hr);
                    }
                    catch { }

                    PostMessage(m_hWnd, Form1.WM_NOTIFY_APP, new IntPtr((int)eventType), new IntPtr(value));

                    break;
                }

                case MediaEventType.MESessionNotifyPresentationTime:
                {
                    Debug.WriteLine(string.Format("{0}: MESessionNotifyPresentationTime, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    HandleNotifyPresentationTime(pEvent);
                    break;
                }

                case MediaEventType.MESessionClosed:
                {
                    Debug.WriteLine(string.Format("{0}: MESessionClosed, Status: 0x{1:x}", eventType.ToString(), eventStatus));

                    m_hCloseEvent.Set();

                    break;
                }

                default:
                    Debug.WriteLine(string.Format("{0}: Event", eventType.ToString()));
                    break;
                }
            }
            catch (Exception e)
            {
                excpt = e;
            }
            finally
            {
                if (eventData != null)
                {
                    eventData.Clear();
                }
            }

            // Request another event.
            if (eventType != MediaEventType.MESessionClosed)
            {
                hr = m_pMediaSession.BeginGetEvent(this, null);
                MFError.ThrowExceptionForHR(hr);
            }

            if (excpt == null)
            {
                hr = HResult.S_OK;
            }
            else
            {
                hr = (HResult)Marshal.GetHRForException(excpt);
            }

            return(hr);
        }
Example #35
0
 public static extern void MFScheduleWorkItemEx(
     IMFAsyncResult pResult,
     long Timeout,
     long pKey);
Example #36
0
        // Callbacks
        // Callback when a video sample is released.
        public void OnSampleFree(IMFAsyncResult pResult)
        {
            object pObject = null;
            IMFSample pSample = null;

            try
            {
                // Get the sample from the async result object.
                int hr = pResult.GetStatus();
                MFError.ThrowExceptionForHR(hr);

                hr = pResult.GetObject(out pObject);
                MFError.ThrowExceptionForHR(hr);
                pSample = (IMFSample)pObject;

                // If this sample was submitted for a frame-step, then the frame step is complete.
                if (m_FrameStep.state == FrameStepRate.Scheduled)
                {
                    if (m_FrameStep.CompareSample(pSample))
                    {
                        // Notify the EVR.
                        CompleteFrameStep(pSample);
                    }

                    // Note: Although pObject is also an IUnknown pointer, it's not guaranteed
                    // to be the exact pointer value returned via QueryInterface, hence the
                    // need for the second QI.
                }

                lock (this)
                {
                    if (MFGetAttributeUINT32Alt(pSample, MFSamplePresenter_SampleCounter, -1) == m_TokenCounter)
                    {
                        // Return the sample to the sample pool.
                        m_SamplePool.ReturnSample(pSample);

                        // Now that a free sample is available, process more data if possible.
                        ProcessOutputLoop();
                    }
                    else
                    {
                        Marshal.ReleaseComObject(pSample);
                    }
                }

            }
            catch (Exception e)
            {
                int hr = Marshal.GetHRForException(e);
                NotifyEvent(EventCode.ErrorAbort, new IntPtr(hr), IntPtr.Zero);
            }
            finally
            {
                //SafeRelease(pObject); pObject = null;
                //SafeRelease(pSample);
                //SafeRelease(pResult);
            }
        }
Example #37
0
 public static extern void MFEndRegisterWorkQueueWithMMCSS(
     [In] IMFAsyncResult pResult,
     out int pdwTaskId);
 public HResult Invoke(IMFAsyncResult pAsyncResult)
 {
     m_onInvokeMethod(pAsyncResult);
     return(HResult.S_OK);
 }
Example #39
0
 public static extern void MFEndUnregisterWorkQueueWithMMCSS(
     [In] IMFAsyncResult pResult);
Example #40
0
 public int Invoke(IMFAsyncResult pAsyncResult)
 {
     try
     {
         OnDispatchWorkItem(pAsyncResult);
     }
     finally
     {
         SafeRelease(pAsyncResult);
     }
     return S_Ok;
 }
Example #41
0
 public HResult EndWrite(IMFAsyncResult pResult, out int pcbWritten)
 {
     throw new NotImplementedException();
 }
Example #42
0
        //-------------------------------------------------------------------
        // Name: OnDispatchWorkItem
        // Description: Callback for MFPutWorkItem.
        //-------------------------------------------------------------------
        void OnDispatchWorkItem(IMFAsyncResult pAsyncResult)
        {
            int hr;

            // Called by work queue thread. Need to hold the critical section.
            lock (this)
            {
                object pState = null;

                hr = pAsyncResult.GetState(out pState);
                MFError.ThrowExceptionForHR(hr);

                try
                {
                    // The state object is a CAsncOperation object.
                    CAsyncOperation pOp = (CAsyncOperation)pState;

                    CAsyncOperation.StreamOperation op = pOp.m_op;

                    switch (op)
                    {
                        case CAsyncOperation.StreamOperation.OpStart:
                        case CAsyncOperation.StreamOperation.OpRestart:
                            // Send MEStreamSinkStarted.
                            QueueEvent(MediaEventType.MEStreamSinkStarted, Guid.Empty, 0, null);

                            // Kick things off by requesting two samples...
                            QueueEvent(MediaEventType.MEStreamSinkRequestSample, Guid.Empty, 0, null);
                            QueueEvent(MediaEventType.MEStreamSinkRequestSample, Guid.Empty, 0, null);

                            // There might be samples queue from earlier (ie, while paused).
                            ProcessSamplesFromQueue(FlushState.WriteSamples);
                            break;

                        case CAsyncOperation.StreamOperation.OpStop:
                            // Drop samples from queue.
                            ProcessSamplesFromQueue(FlushState.DropSamples);

                            // Send the event even if the previous call failed.
                            QueueEvent(MediaEventType.MEStreamSinkStopped, Guid.Empty, 0, null);
                            break;

                        case CAsyncOperation.StreamOperation.OpPause:
                            QueueEvent(MediaEventType.MEStreamSinkPaused, Guid.Empty, 0, null);
                            break;

                        case CAsyncOperation.StreamOperation.OpProcessSample:
                        case CAsyncOperation.StreamOperation.OpPlaceMarker:
                            DispatchProcessSample(pOp);
                            break;

                        case CAsyncOperation.StreamOperation.OpFinalize:
                            DispatchFinalize(pOp);
                            break;
                    }
                }
                finally
                {
                    SafeRelease(pState);
                }
            }
        }
Example #43
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);
        }
    }
Example #44
0
        int m_WorkQueueId; // ID of the work queue for asynchronous operations.

        #endregion Fields

        #region Constructors

        public CWavStream(CWavSink pParent, IMFByteStream pByteStream)
        {
            int hr;
            TRACE("CWavStream::CWavStream");

            m_SampleQueue = new Queue();
            m_state = State.TypeNotSet;
            m_IsShutdown = false;
            m_pSink = null;
            m_pEventQueue = null;
            m_pByteStream = null;

            m_pCurrentType = null;
            m_pFinalizeResult = null;
            m_StartTime = 0;
            m_cbDataWritten = 0;
            m_WorkQueueId = 0;

            Debug.Assert(pParent != null);
            Debug.Assert(pByteStream != null);

            MFByteStreamCapabilities dwCaps = MFByteStreamCapabilities.None;
            const MFByteStreamCapabilities dwRequiredCaps = (MFByteStreamCapabilities.IsWritable | MFByteStreamCapabilities.IsSeekable);

            // Make sure the byte stream has the necessary caps bits.
            hr = pByteStream.GetCapabilities(out dwCaps);
            MFError.ThrowExceptionForHR(hr);

            if ((dwCaps & dwRequiredCaps) != dwRequiredCaps)
            {
                throw new COMException("stream doesn't have required caps", E_Fail);
            }

            // Move the file pointer to leave room for the RIFF headers.
            hr = pByteStream.SetCurrentPosition(Marshal.SizeOf(typeof(WAV_FILE_HEADER)));
            MFError.ThrowExceptionForHR(hr);

            // Create the event queue helper.
            hr = MFExternAlt.MFCreateEventQueue(out m_pEventQueue);
            MFError.ThrowExceptionForHR(hr);

            // Allocate a new work queue for async operations.
            hr = MFExtern.MFAllocateWorkQueue(out m_WorkQueueId);
            MFError.ThrowExceptionForHR(hr);

            m_pByteStream = pByteStream;
            m_pSink = pParent;
        }
Example #45
0
    ///////////////////////////////////////////////////////////////////////
    //  Name: Invoke
    //  Description:  Callback for asynchronous BeginGetEvent method.
    //
    //  pAsyncResult: Pointer to the result.
    /////////////////////////////////////////////////////////////////////////
    int IMFAsyncCallback.Invoke(IMFAsyncResult pAsyncResult)
    {
        // Make sure we *never* leave this entry point with an exception
        try
        {
            int 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 (m_hrStatus == 862022) // NS_S_DRM_MONITOR_CANCELLED
            {
                m_hrStatus = MFError.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 S_Ok;
        }
        catch (Exception e)
        {
            return Marshal.GetHRForException(e);
        }
    }
Example #46
0
 public static extern void MFEndCreateFile(
     [In] IMFAsyncResult pResult,
     out IMFByteStream ppFile);
Example #47
0
        public int EndGetEvent(IMFAsyncResult pResult, out IMFMediaEvent ppEvent)
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                int hr;
                m_Log.WriteLine("-EndGetEvent");
                ppEvent = null;

                lock (this)
                {
                    CheckShutdown();
                    hr = m_pEventQueue.EndGetEvent(pResult, out ppEvent);
                }
                return S_Ok;
            }
            catch (Exception e)
            {
                ppEvent = null;
                return Marshal.GetHRForException(e);
            }
        }