示例#1
0
        /// <summary>
        /// Called on a new thread to process events from the graph.  The thread
        /// exits when the graph finishes.
        /// </summary>
        private void EventWait()
        {
            // Returned when GetEvent is called but there are no events
            const int E_ABORT = unchecked ((int)0x80004004);

            int       hr;
            IntPtr    p1, p2;
            EventCode ec;
            EventCode exitCode = 0;

            IMediaEvent mediaEvent = (IMediaEvent)this.filterGraph;

            do
            {
                // Read the event
                for (hr = mediaEvent.GetEvent(out ec, out p1, out p2, 100);
                     hr >= 0;
                     hr = mediaEvent.GetEvent(out ec, out p1, out p2, 100))
                {
                    switch (ec)
                    {
                    // If the clip is finished playing
                    case EventCode.EndOfSegment:
                    case EventCode.StreamControlStopped:
                    case EventCode.Complete:
                    case EventCode.ErrorAbort:
                    case EventCode.UserAbort:
                        exitCode = ec;

                        // Release any resources the message allocated
                        hr = mediaEvent.FreeEventParams(ec, p1, p2);
                        DsError.ThrowExceptionForHR(hr);
                        break;

                    default:
                        // Release any resources the message allocated
                        hr = mediaEvent.FreeEventParams(ec, p1, p2);
                        DsError.ThrowExceptionForHR(hr);
                        break;
                    }
                }

                // If the error that exited the loop wasn't due to running out of events
                if (hr != E_ABORT)
                {
                    DsError.ThrowExceptionForHR(hr);
                }
            }while (exitCode == 0);

            // Send an event saying we are complete
            if (this.Completed != null)
            {
                var ca = new DESCompletedArgs(exitCode);
                this.Completed(this, ca);
            }

            // Exit the thread
        }
示例#2
0
        private void Completed(object sender, System.EventArgs e)
        {
            DESCompletedArgs ca = e as DESCompletedArgs;

            Console.WriteLine(ca.Result.ToString());
            ds.Seek(0);
            //ds.Dispose();
            //ds = null;
            //GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
示例#3
0
        /// <summary>
        /// Called on a new thread to process events from the graph.  The thread
        /// exits when the graph finishes.  Cancelling is done here.
        /// </summary>
        private void EventWait()
        {
            // Returned when GetEvent is called but there are no events
            const int E_ABORT = unchecked ((int)0x80004004);

            int       hr;
            IntPtr    p1, p2;
            EventCode ec;
            EventCode exitCode = 0;

            IMediaEvent pEvent = (IMediaEvent)m_pGraph;

            do
            {
                // Read the event
                for (
                    hr = pEvent.GetEvent(out ec, out p1, out p2, 100);
                    hr >= 0 && m_State < ClassState.GraphCompleted;
                    hr = pEvent.GetEvent(out ec, out p1, out p2, 100)
                    )
                {
                    switch (ec)
                    {
                    case EventCode.UserAbort:
                        ChangeState(ClassState.Cancelling);
                        exitCode = ec;
                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DESError.ThrowExceptionForHR(hr);

                        break;

                    // If the clip is finished playing
                    case EventCode.Complete:
                    case EventCode.ErrorAbort:
                        ChangeState(ClassState.GraphCompleting);
                        exitCode = ec;

                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DESError.ThrowExceptionForHR(hr);
                        break;

                    // Walked past the end of a video file, send an event
                    case EC_VideoFileComplete:
                        if (FileCompleted != null)
                        {
                            MediaFile         mf = m_Video.File(p1.ToInt32());
                            FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Video);
                            FileCompleted(this, ca);
                        }
                        break;

                    // Walked past the end of a video file, send an event
                    case EC_AudioFileComplete:
                        if (FileCompleted != null)
                        {
                            MediaFile         mf = m_Audio.File(p1.ToInt32());
                            FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Audio);
                            FileCompleted(this, ca);
                        }
                        break;

                    default:
                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DESError.ThrowExceptionForHR(hr);
                        break;
                    }
                }

                // If the error that exited the loop wasn't due to running out of events
                if (hr != E_ABORT)
                {
                    DESError.ThrowExceptionForHR(hr);
                }
                //FilterState fs;
                //m_pControl.GetState(200, out fs);
                ////DESError.ThrowExceptionForHR(hr);
            } while (m_State < ClassState.GraphCompleting);

            // If the user cancelled
            if (m_State == ClassState.Cancelling && m_pControl != null)
            {
                // Stop the graph, send an appropriate exit code
                hr       = m_pControl.Stop();
                exitCode = EventCode.UserAbort;
            }

            if (m_State == ClassState.GraphCompleting)
            {
                m_State = ClassState.GraphCompleted;
            }
            else
            {
                m_State = ClassState.Cancelled;
            }

            threadCompleted = true;

            // Send an event saying we are complete
            if (this.ThreadFinished != null)
            {
                DESCompletedArgs ca = new DESCompletedArgs(exitCode);
                this.ThreadFinished(this, ca);
            }
        } // Exit the thread
示例#4
0
    /// <summary>
    /// Called on a new thread to process events from the graph.  The thread
    /// exits when the graph finishes.  Cancelling is done here.
    /// </summary>
    private void EventWait()
    {
      // Returned when GetEvent is called but there are no events
      const int E_ABORT = unchecked((int)0x80004004);

      int hr;
      IntPtr p1, p2;
      EventCode ec;
      EventCode exitCode = 0;

      IMediaEvent pEvent = (IMediaEvent)m_pGraph;

      do
      {
        // Read the event
        for (
            hr = pEvent.GetEvent(out ec, out p1, out p2, 100);
            hr >= 0 && m_State < ClassState.GraphCompleted;
            hr = pEvent.GetEvent(out ec, out p1, out p2, 100)
            )
        {
          switch (ec)
          {
            case EventCode.UserAbort:
              ChangeState(ClassState.Cancelling);
              exitCode = ec;
              // Release any resources the message allocated
              hr = pEvent.FreeEventParams(ec, p1, p2);
              DESError.ThrowExceptionForHR(hr);

              break;
            // If the clip is finished playing
            case EventCode.Complete:
            case EventCode.ErrorAbort:
              ChangeState(ClassState.GraphCompleting);
              exitCode = ec;

              // Release any resources the message allocated
              hr = pEvent.FreeEventParams(ec, p1, p2);
              DESError.ThrowExceptionForHR(hr);
              break;

            // Walked past the end of a video file, send an event
            case EC_VideoFileComplete:
              if (FileCompleted != null)
              {
                MediaFile mf = m_Video.File(p1.ToInt32());
                FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Video);
                FileCompleted(this, ca);
              }
              break;

            // Walked past the end of a video file, send an event
            case EC_AudioFileComplete:
              if (FileCompleted != null)
              {
                MediaFile mf = m_Audio.File(p1.ToInt32());
                FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Audio);
                FileCompleted(this, ca);
              }
              break;

            default:
              // Release any resources the message allocated
              hr = pEvent.FreeEventParams(ec, p1, p2);
              DESError.ThrowExceptionForHR(hr);
              break;
          }
        }

        // If the error that exited the loop wasn't due to running out of events
        if (hr != E_ABORT)
        {
          DESError.ThrowExceptionForHR(hr);
        }
        //FilterState fs;
        //m_pControl.GetState(200, out fs);
        ////DESError.ThrowExceptionForHR(hr);

      } while (m_State < ClassState.GraphCompleting);

      // If the user cancelled
      if (m_State == ClassState.Cancelling && m_pControl != null)
      {
        // Stop the graph, send an appropriate exit code
        hr = m_pControl.Stop();
        exitCode = EventCode.UserAbort;
      }

      if (m_State == ClassState.GraphCompleting)
      {
        m_State = ClassState.GraphCompleted;
      }
      else
      {
        m_State = ClassState.Cancelled;
      }

      threadCompleted = true;

      // Send an event saying we are complete
      if (this.ThreadFinished != null)
      {
        DESCompletedArgs ca = new DESCompletedArgs(exitCode);
        this.ThreadFinished(this, ca);
      }
    } // Exit the thread