Ejemplo n.º 1
0
        private void TestCalibrate()
        {
            //No hardware
            IMediaEventSink mes;
            IFilterGraph2   FilterGraph;
            int             hr;

            FilterGraph = (IFilterGraph2) new FilterGraph();

            hr = FilterGraph.RenderFile("foo.avi", null);
            DsError.ThrowExceptionForHR(hr);

            mes = (IMediaEventSink)FilterGraph;
            IMediaEvent pEvent = (IMediaEvent)FilterGraph;


            int ret = 0;

            IntPtr eventHandle = IntPtr.Zero;

            hr = pEvent.GetEventHandle(out eventHandle);
            DsError.ThrowExceptionForHR(hr);

            hr = _extDevice.Calibrate(eventHandle, ExtTransportEdit.Active, out ret);
            //DsError.ThrowExceptionForHR(hr); //E_NOTIMPL , but atleast it's called.

            hr = _extDevice.Calibrate(eventHandle, 0, out ret);
            //DsError.ThrowExceptionForHR(hr); //E_NOTIMPL , but atleast it's called.
        }
Ejemplo n.º 2
0
        public Capture(Control hWin, string FileName)
        {
            try
            {
                int    hr;
                IntPtr hEvent;

                m_sFileName = FileName;

                SetupGraph(hWin, FileName);

                // Get the event handle the graph will use to signal
                // when events occur
                hr = m_mediaEvent.GetEventHandle(out hEvent);
                DsError.ThrowExceptionForHR(hr);

                // Wrap the graph event with a ManualResetEvent
                m_mre = new ManualResetEvent(false);
#if USING_NET11
                m_mre.Handle = hEvent;
#else
                m_mre.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(hEvent, true);
#endif

                // Create a new thread to wait for events
                Thread t = new Thread(new ThreadStart(this.EventWait));
                t.Name = "Media Event Thread";
                t.Start();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        /// <summary>Load a video/audio file and prepare to play it</summary>
        public void LoadFile(string file)
        {
            try
            {
                if (m_filter_graph != null)
                {
                    throw new Exception("Reusing this Video object is not allowed");
                }

                m_file         = file;
                m_filter_graph = new FilterGraph() as IFilterGraph2;
                if (m_filter_graph == null)
                {
                    throw new Exception("failed to create direct show filter graph");
                }

                // Have the filter graph construct the appropriate graph automatically
                DsError.ThrowExceptionForHR(m_filter_graph.RenderFile(file, null));

                                #if DEBUG
                // Allows you to view the graph with GraphEdit File/Connect
                m_ds_rot = new DsROTEntry(m_filter_graph);
                                #endif

                // Grab some other interfaces
                m_media_event    = m_filter_graph as IMediaEvent;
                m_media_ctrl     = m_filter_graph as IMediaControl;
                m_media_position = m_filter_graph as IMediaPosition;
                if (m_media_event == null)
                {
                    throw new Exception("failed to obtain a direct show IMediaEvent interface");
                }
                if (m_media_ctrl == null)
                {
                    throw new Exception("failed to obtain a direct show IMediaControl interface");
                }
                if (m_media_position == null)
                {
                    throw new Exception("failed to obtain a direct show IMediaPosition interface");
                }

                // Grab optional interfaces
                m_video_window = m_filter_graph as IVideoWindow;
                m_basic_video  = m_filter_graph as IBasicVideo;
                m_basic_audio  = m_filter_graph as IBasicAudio;

                // If this is an audio-only clip, get_Visible() won't work. Also, if this
                // video is encoded with an unsupported codec, we won't see any video,
                // although the audio will work if it is of a supported format.
                if (m_video_window != null)
                {
                    const int E_NOINTERFACE = unchecked ((int)0x80004002);

                    // Use put Visible since we want to hide the video window
                    // till we're ready to show it anyway
                    int hr = m_video_window.put_Visible(OABool.False);
                    if (hr == E_NOINTERFACE)
                    {
                        m_video_window = null;
                    }
                    else
                    {
                        DsError.ThrowExceptionForHR(hr);
                    }
                }

                // Get the event handle the graph will use to signal when events occur, wrap it in a ManualResetEvent
                IntPtr media_event;
                DsError.ThrowExceptionForHR(m_media_event.GetEventHandle(out media_event));
                m_event = new ManualResetEvent(false)
                {
                    SafeWaitHandle = new SafeWaitHandle(media_event, false)
                };

                // Create a new thread to wait for events
                m_media_event_thread = new Thread(MediaEventWait)
                {
                    Name = "Media Event Thread"
                };
                m_media_event_thread.Start();

                if (FileLoaded != null)
                {
                    FileLoaded(this, file);
                }
            }
            catch { Dispose(); throw; }
                        #if DEBUG
            GC.Collect();             // Double check to make sure we aren't releasing something important.
            GC.WaitForPendingFinalizers();
                        #endif
        }