/// <summary>
        /// Startet den Graphen.
        /// </summary>
        /// <exception cref="InvalidOperationException">Der Graph konnte nicht gestartet werden.</exception>
        public void Run()
        {
            // Try start
            int result = GraphAsFilter.Run(0);

            // Run the graph
            if (result < 0)
            {
                throw new InvalidOperationException(string.Format("graph not started, error is 0x{0:x}", result));
            }
        }
        /// <summary>
        /// Gibt alle internen Strukturen frei.
        /// </summary>
        private void DestroyGraph()
        {
            // Get rid of clock
            DisposeClock();

            // Try stop and delete all filters
            if (null != m_Graph)
            {
                try
                {
                    // Stop self
                    GraphAsFilter.Stop();
                }
                catch
                {
                }
            }

            // Filters first
            foreach (var filter in m_Filters.Values)
            {
                filter.Dispose();
            }

            // Clear list
            m_Filters.Clear();

            // Forward
            using (m_Register)
                m_Register = null;

            // Must cleanup COM references
            BDAEnvironment.Release(ref m_Graph);

            // Must cleanup file
            using (m_LogFile)
                m_LogFile = null;

            // Clear helpers and reset flags
            m_VideoWindowCreated = false;
            m_VideoPID           = 0;
            m_AudioPID           = 0;

            // TS Filter
            using (InjectorFilter)
                InjectorFilter = null;
        }
        /// <summary>
        /// Erzuegt den Anzeigegraphen.
        /// </summary>
        /// <param name="mpeg4">Gesetzt für H.264 Bildinformationen - ansonsten wird MPEG-2 erwartet.</param>
        /// <param name="ac3">Gesetzt für AC3 Toninformationen - ansonsten wird MP2 erwartet.</param>
        public void Show(bool mpeg4, bool ac3)
        {
            // Startup
            bool firstCall = PrepareShow();

            // Leave fullscreen before stopping graph
            bool fullscreen = FullScreen;

            if (fullscreen)
            {
                FullScreen = false;
            }

            // Stop the graph
            Stop();

            // Forget the clock
            DisposeClock();

            // Remove all filters not created by us
            var noRemove = new HashSet <IntPtr>(m_Filters.Values.Select(f => f.Interface));

            ((IFilterGraph)m_Graph).InspectFilters(filter =>
            {
                // Create report structure
                var info = new FilterInfo();

                // Load it
                filter.QueryFilterInfo(ref info);

                // Forget about graph
                BDAEnvironment.Release(ref info.Graph);

                // Process using raw interfaces
                using (var id = ComIdentity.Create(filter))
                    if (!noRemove.Contains(id.Interface))
                    {
                        try
                        {
                            // Repoert
                            if (DirectShowTraceSwitch.Enabled)
                            {
                                Trace.WriteLine(string.Format(Properties.Resources.Trace_RemoveFilter, info.Name), DirectShowTraceSwitch.DisplayName);
                            }

                            // Process
                            DirectShowObject.RemoveFilter(id.Interface);
                        }
                        catch (Exception e)
                        {
                            // Report
                            Trace.WriteLine(string.Format(Properties.Resources.Trace_Exception_RemoveFilter, info.Name, e.Message), DirectShowTraceSwitch.DisplayName);
                        }
                    }
            });

            // Create media types
            var videoType = CreateVideoType(mpeg4, UseCyberlink);
            var audioType = CreateAudioType(ac3);

            // Configure injection pins
            InjectorFilter.SetAudioType(audioType);
            InjectorFilter.SetVideoType(videoType);

            // Helper
            var audioConnected = false;
            var videoConnected = false;

            // Pre-loaded decoders
            LoadDecoder(mpeg4 ? H264Decoder : MPEG2Decoder, mpeg4 ? "HDTV-Video" : "SDTV-Video", decoder => videoConnected = TryDirectConnect(decoder, InjectorFilter.VideoPin, videoType));
            LoadDecoder(ac3 ? AC3Decoder : MP2Decoder, ac3 ? "AC3-Audio" : "MP2-Audio", decoder => audioConnected          = TryDirectConnect(decoder, InjectorFilter.AudioPin, audioType));

            // Create display
            if (!audioConnected)
            {
                DirectShowObject.Render(InjectorFilter.AudioPin.Interface);
            }
            if (!videoConnected)
            {
                DirectShowObject.Render(InjectorFilter.VideoPin.Interface);
            }

            // Show for the first time
            var vmr = VMR;

            if (firstCall)
            {
                if (vmr != null)
                {
                    if (m_VideoWindow != null)
                    {
                        // Respect window settings
                        vmr.ClippingWindow = m_VideoWindow;
                        vmr.AdjustSize(m_VideoWindow);
                    }
                }
            }

            // Use it
            m_Clock = new NoMarshalComObjects.ReferenceClock(Activator.CreateInstance(Type.GetTypeFromCLSID(Constants.CLSID_SystemClock)), true);

            // Attach to graph
            GraphAsFilter.SetSyncSource(m_Clock.ComInterface);

            // Time to restart the graph
            Run();

            // Reinstall volume
            if (m_LastVolume.HasValue)
            {
                Volume = m_LastVolume.Value;
            }

            // Reinstall picture parameters
            if (m_PictureParameters != null)
            {
                if (vmr != null)
                {
                    m_PictureParameters.Update(vmr);
                }
            }

            // Back to full screen mode
            if (fullscreen)
            {
                FullScreen = true;
            }
        }
 /// <summary>
 /// Unterbricht den Graphen.
 /// </summary>
 public void Pause()
 {
     // Forward
     GraphAsFilter.Pause();
 }
 /// <summary>
 /// Hält den Graphen an - Fehler werden dabei ignoriert.
 /// </summary>
 public virtual void Stop()
 {
     // Forward - no error detectable
     GraphAsFilter.Stop();
 }