示例#1
0
        /// <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;
        }
示例#2
0
 /// <summary>
 /// Gibt den Zähler der Zeitbasis frei.
 /// </summary>
 private void DisposeClock()
 {
     // Process
     using (m_Clock)
         m_Clock = null;
 }