/// <summary> /// Versucht den DVB.NET Datenstrom direkt mit dem zugehörigen Decoder zu verbinden. /// </summary> /// <param name="decoder">Ein manuell angelegter Decoder.</param> /// <param name="source">Der zu verwendende Ausgang.</param> /// <param name="mediaType">Das verwendete Format.</param> /// <returns>Gesetzt, wenn die Verbindung aufgebaut wurde.</returns> private bool TryDirectConnect(TypedComIdentity <IBaseFilter> decoder, OutputPin source, MediaType mediaType) { // In normal cases we should directly connect to the filter so try var connected = false; // Try manual connect decoder.InspectAllPins(p => p.QueryDirection() == PinDirection.Input, pin => { // Skip on error try { // Get the raw interface for the media type var type = mediaType.GetReference(); // Process using (var iFace = ComIdentity.Create <IPin>(pin)) source.Connect(iFace.Interface, type); // Did it connected = true; } catch (Exception) { } // First pin only - even if it can not be used! return(false); }); // Failed if (!connected) { return(false); } // Find the output of the decoder and render it decoder.InspectAllPins(p => p.QueryDirection() == PinDirection.Output, pin => { // Create helper using (var pinWrapper = ComIdentity.Create <IPin>(pin)) DirectShowObject.Render(pinWrapper.Interface); // Did it return(false); }); // Report return(connected); }
/// <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; } }