예제 #1
0
    // FIXME this needs some work, to be completely in-tune with needs.
    public void MediaEventLoop(Action <double> UpdateProgress)
    {
        mediaEvent.CancelDefaultHandling(EventCode.StateChange);
        //mediaEvent.CancelDefaultHandling(EventCode.Starvation);
        while (stopMediaEventLoop == false)
        {
            try
            {
                EventCode ev;
                IntPtr    p1, p2;
                if (mediaEvent.GetEvent(out ev, out p1, out p2, 0) == 0)
                {
                    switch (ev)
                    {
                    case EventCode.Complete:
                        Stopping.Fire(this, null);
                        if (UpdateProgress != null)
                        {
                            UpdateProgress(source.PercentageCompleted);
                        }
                        return;

                    case EventCode.StateChange:
                        FilterState state = (FilterState)p1.ToInt32();
                        if (state == FilterState.Stopped || state == FilterState.Paused)
                        {
                            Stopping.Fire(this, null);
                        }
                        else if (state == FilterState.Running)
                        {
                            Starting.Fire(this, null);
                        }
                        break;
                        // FIXME add abort and stuff, and propagate this.
                    }
                    //                        Trace.WriteLine(ev.ToString() + " " + p1.ToInt32());
                    mediaEvent.FreeEventParams(ev, p1, p2);
                }
                else
                {
                    if (UpdateProgress != null)
                    {
                        UpdateProgress(source.PercentageCompleted);
                    }
                    // FiXME use AutoResetEvent
                    Thread.Sleep(100);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("MediaEventLoop: " + e);
            }
        }
    }
예제 #2
0
        /// <summary>
        /// Test all methods
        /// </summary>
        public void DoTests()
        {
            int       hr;
            IntPtr    hEvent;
            IntPtr    p1, p2;
            EventCode ec;

            BuildGraph();

            hr = m_mediaEvent.GetEventHandle(out hEvent);
            DsError.ThrowExceptionForHR(hr);

            ManualResetEvent mre = new ManualResetEvent(false);

            mre.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(hEvent, true);

            // Should get an event before this
            bool b = mre.WaitOne(5000, true);

            Debug.Assert(b, "GetEventHandle");

            // I don't know what event I may get, so I don't know how to check it

            hr = m_mediaEvent.GetEvent(out ec, out p1, out p2, 0);
            DsError.ThrowExceptionForHR(hr);

            hr = m_mediaEvent.FreeEventParams(ec, p1, p2);
            DsError.ThrowExceptionForHR(hr);

            hr = m_mediaEvent.CancelDefaultHandling(EventCode.Repaint);
            DsError.ThrowExceptionForHR(hr);

            hr = m_mediaEvent.RestoreDefaultHandling(EventCode.Repaint);
            DsError.ThrowExceptionForHR(hr);

            // The clip is 4 seconds long, so timeout in 5
            hr = m_mediaEvent.WaitForCompletion(5000, out ec);
            DsError.ThrowExceptionForHR(hr);

            // The video should have successfully played
            Debug.Assert(ec == EventCode.Complete, "WaitForCompletion");
        }