예제 #1
0
        public void Stop()
        {
            if (State != ContainerState.CS_Running)
            {
                return;
            }
            if ((TestControl == null) || (MediaControl == null))
            {
                throw new VideoException("Internal error in AV engine");
            }
            Exception ex         = null;
            Action    StopAction = new Action(() =>
            {
                try
                {
                    int StreamState     = 0;
                    State               = ContainerState.CS_Stopped;
                    VideoWindow.Visible = 0;
                    TestControl.GetStreamHealth(ref StreamState);
                    TestControl.ControlStream(2);
                    //if (StreamState > 0)// TODO why it works fine that way? why it locks instead sometimes?
                    {
                        System.Diagnostics.Trace.WriteLine("Trying to close DirectShow " + StreamState.ToString());
                        MediaControl.Stop();
                        System.Diagnostics.Trace.WriteLine("DirectShow closed");
                    }
                    //else
                    {
                        //System.Diagnostics.Trace.WriteLine("Bypassing DirectShow close as it is not safe " + StreamState.ToString());
                        //MediaControl.StopWhenReady();
                        //System.Diagnostics.Trace.WriteLine("DirectShow lazy close initiated");
                    }
                    TestControl.ControlStream(0);
                }
                catch (Exception e)
                {
                    ex = e;
                }
            });
            IAsyncResult StopResult = StopAction.BeginInvoke(null, null);

            if (RTSP)
            {
                ProceedAction(9, 10, StopResult, ref ex);
            }
            else
            {
                // skip TEARDOWN step
                ProceedAction(9, 9, StopResult, ref ex);
            }
        }
예제 #2
0
        public void Stop()
        {
            if (State != ContainerState.CS_Running)
            {
                return;
            }
            if ((TestControl == null) || (MediaControl == null))
            {
                throw new VideoException("Internal error in AV engine");
            }
            Exception ex         = null;
            Action    StopAction = new Action(() =>
            {
                try
                {
                    int StreamState     = 0;
                    State               = ContainerState.CS_Stopped;
                    VideoWindow.Visible = 0;
                    TestControl.GetStreamHealth(ref StreamState);
                    TestControl.ControlStream(2);
                    //if (StreamState > 0)// TODO why it works fine that way? why it locks instead sometimes?
                    {
                        System.Diagnostics.Trace.WriteLine("Trying to close DirectShow " + StreamState.ToString());
                        MediaControl.Stop();
                        System.Diagnostics.Trace.WriteLine("DirectShow closed");
                    }
                    //else
                    {
                        //System.Diagnostics.Trace.WriteLine("Bypassing DirectShow close as it is not safe " + StreamState.ToString());
                        //MediaControl.StopWhenReady();
                        //System.Diagnostics.Trace.WriteLine("DirectShow lazy close initiated");
                    }
                    TestControl.ControlStream(0);
                }
                catch (Exception e)
                {
                    ex = e;
                }
            });
            IAsyncResult StopResult = StopAction.BeginInvoke(null, null);

#if true
            ProceedAction(9, 10, StopResult, ref ex);
#else
            if (EventConsumer != null)
            {
                LogActivity(Timeout, 9, 10, StopResult);
            }
            else
            {
                StopResult.AsyncWaitHandle.WaitOne(Timeout);
            }
            if (!StopResult.IsCompleted)
            {
                throw new VideoException("Connection Timeout");
            }
            if (ex != null)
            {
                ProceedEx(ex);
                //throw ex;
            }
#endif
        }