Example #1
0
        /// <summary>
        /// Beendet die Nutzung dieser Instanz endgültig.
        /// </summary>
        public override void Dispose()
        {
            // Stop and raw TS dump
            StopDump();

            // Stop all
            Stop();

            // Forward to injectors
            using (Injector ts = m_TSInjector)
                if (ts != null)
                {
                    // Forget
                    m_TSInjector = null;

                    // Shut down
                    ts.Inject(null, 0, 0, true, null);
                }

            // Clear AV
            SetAudioType(null);
            SetVideoType(null);

            // Forward to input pin
            using (var pin = m_Pin)
                m_Pin = null;

            // Forget the graph
            BDAEnvironment.Release(ref m_Graph);

            // Forward
            base.Dispose();
        }
        /// <summary>
        /// Ermittelt alle Filter einer bestimmten Art.
        /// </summary>
        /// <param name="category">Die gewünschte Art.</param>
        /// <returns>Liste der Namen.</returns>
        private List <FilterInformation> FindFiltersByCategory(Guid category)
        {
            // Result
            var names = new List <FilterInformation>();

            // Create system device enumerator
            var devEnum = (ICreateDevEnum)Activator.CreateInstance(Type.GetTypeFromCLSID(BDAEnvironment.SystemDeviceEnumeratorClassIdentifier));

            try
            {
                // Get the enumerator
                IEnumMoniker monikers;
                if (devEnum.CreateClassEnumerator(ref category, out monikers, 0) == 0)
                {
                    LoadFromEnumeration(category, "DevicePath", names, monikers);
                }
            }
            finally
            {
                // Back to COM
                BDAEnvironment.Release(ref devEnum);
            }

            // Report
            return(names);
        }
        /// <summary>
        /// Ermittelt zu einem Filter einen ausgangsseitigen Steuerknoten der Topologie.
        /// </summary>
        /// <typeparam name="T">Die Art der benötigten Schnittstelle.</typeparam>
        /// <param name="filter">Ein Filter.</param>
        /// <param name="nodeType">Die Art des Knotens.</param>
        /// <returns>Der gewünschte Knoten.</returns>
        public static T GetOutputControlNode <T>(this TypedComIdentity <IBaseFilter> filter, uint nodeType) where T : class
        {
            // Validate
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            // Attach to alternate interface
            using (var instance = filter.MarshalToManaged())
            {
                // Change type
                var topology = instance.Object as IBDATopology;
                if (topology == null)
                {
                    return(null);
                }

                // Load
                var node   = topology.GetControlNode(0, 1, nodeType);
                var result = node as T;

                // Cleanup
                if (result == null)
                {
                    BDAEnvironment.Release(ref node);
                }

                // Report
                return(result);
            }
        }
Example #4
0
        /// <summary>
        /// Leitet die Daten zu einem Endpunkt um.
        /// </summary>
        /// <param name="receivePin">Der Endpunkt, der die Daten empfangen soll.</param>
        /// <param name="mediaType">Die Art der zu übertragenden Daten.</param>
        public void Connect(IntPtr receivePin, IntPtr mediaType)
        {
            // Inform partner
            var receiver = Marshal.GetObjectForIUnknown(receivePin);

            try
            {
                // Change type
                var pin = (IPin)receiver;

                // We can choose
                if (mediaType == IntPtr.Zero)
                {
                    // Use ours
                    mediaType = m_Types[0].GetReference();

                    // Ask partner
                    if (pin.QueryAccept(mediaType) != 0)
                    {
                        throw new COMException("mediaType", unchecked ((int)0x80040207));
                    }
                }

                // Forward
                ReceiveConnection(receivePin, mediaType);

                // Forward
                pin.ReceiveConnection(Interface, mediaType);
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref receiver);
            }
        }
Example #5
0
        /// <summary>
        /// Liest eine bestimmte Eigenschaft eines eindeutigen Namens.
        /// </summary>
        /// <param name="moniker">Der eindeutige Name.</param>
        /// <param name="property">Name der gewünschten Eigenschaft.</param>
        /// <returns>Wert der Eigenschaft.</returns>
        public static string ReadProperty(this IMoniker moniker, string property)
        {
            // Validate
            if (moniker == null)
            {
                return(null);
            }

            // Guid for reference
            Guid propBag = new Guid("55272a00-42cb-11ce-8135-00aa004bb851");

            // Prepare for errors
            try
            {
                // Change interface
                var props = moniker.BindToStorage(null, null, ref propBag);
                try
                {
                    // Report
                    return(((IPropertyBag)props).Get <string>(property));
                }
                finally
                {
                    // Cleanup
                    BDAEnvironment.Release(ref props);
                }
            }
            catch
            {
                // Do nothing in case of ANY error
                return(null);
            }
        }
Example #6
0
        /// <summary>
        /// Gibt alle sekundären Ressourcen zu dieser Formatbeschreibung
        /// frei.
        /// <seealso cref="CopyTo"/>
        /// </summary>
        public void FreeMemory()
        {
            // Check for holder
            BDAEnvironment.Release(ref Holder);

            // Reset
            Format = null;
        }
Example #7
0
        /// <summary>
        /// Ändert die zu verwendende Speicherverwaltung.
        /// </summary>
        /// <param name="allocator">Die neue Speicherverwaltung.</param>
        /// <param name="bReadOnly">Gesetzt, wenn auf die Speicherverwaltung nur lesend zugegriffen werden darf.</param>
        public void NotifyAllocator(IMemAllocator allocator, bool bReadOnly)
        {
            // Cleanup
            BDAEnvironment.Release(ref m_Allocator);

            // Remember
            m_AllocatorReadOnly = bReadOnly;
            m_Allocator         = allocator;
        }
Example #8
0
        /// <summary>
        /// Trennt den Endpunkt von anderen.
        /// </summary>
        public void Disconnect()
        {
            // Detach all helper
            m_NotifySink = null;
            m_MemSink    = null;

            // Release
            BDAEnvironment.Release(ref m_MemPin);
            BDAEnvironment.Release(ref m_Connected);

            // Reset
            m_ConnectType.Dispose();
            m_ConnectType = new MediaType();
        }
Example #9
0
        /// <summary>
        /// Legt die Referenzuhr für diesen Filter fest.
        /// </summary>
        /// <param name="clock">Die neue Referenzuhr.</param>
        public void SetSyncSource(IntPtr clock)
        {
            // Proper cleanup
            BDAEnvironment.Release(ref m_Clock);

            // Remember
            m_Clock = clock;

            // Proper lock
            if (m_Clock != IntPtr.Zero)
            {
                Marshal.AddRef(m_Clock);
            }
        }
        /// <summary>
        /// Füllt eine Liste mit Filterinformationen aus einer Auflistung.
        /// </summary>
        /// <param name="category">Die Art des Filters.</param>
        /// <param name="uniqueProp">Die Eigenschaft, die als eindeutige Kennung verwendet werden soll.</param>
        /// <param name="list">Die Informationen.</param>
        /// <param name="monikers">Die Auflistung.</param>
        public void LoadFromEnumeration(Guid category, string uniqueProp, List <FilterInformation> list, IEnumMoniker monikers)
        {
            // Nothing to do
            if (monikers == null)
            {
                return;
            }

            // With cleanup
            try
            {
                // Process all
                for (; ;)
                {
                    using (var array = new COMArray(1))
                    {
                        // Load
                        uint count;
                        if (monikers.Next(1, array.Address, out count) != 0)
                        {
                            break;
                        }

                        // Load object
                        if (count != 1)
                        {
                            continue;
                        }

                        // Load the one
                        var moniker = array.GetObject <IMoniker>(0);
                        try
                        {
                            // Remember
                            list.Add(new FilterInformation(category, moniker.ReadProperty("FriendlyName"), moniker.ReadProperty(uniqueProp), m_MediaDevices));
                        }
                        finally
                        {
                            // Cleanup
                            BDAEnvironment.Release(ref moniker);
                        }
                    }
                }
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref monikers);
            }
        }
        /// <summary>
        /// Erzeugt eine neue Instanz.
        /// </summary>
        /// <typeparam name="DataType">Die Art der Daten.</typeparam>
        /// <param name="interface">Die zu verwendende Schnittstelle.</param>
        /// <returns>Eine neue Zugriffsinstanz.</returns>
        public static IKsPropertySet <DataType> Create <DataType>(IntPtr @interface)
            where DataType : struct
        {
            // None
            if (@interface == null)
            {
                return(null);
            }

            // Try to access the interface
            var com = ComIdentity.TryQueryInterface(@interface, typeof(IKsPropertySet));

            if (com == IntPtr.Zero)
            {
                return(null);
            }

            // Be safe
            try
            {
                // Create the wrapper
                using (var typed = new TypedComIdentity <IKsPropertySet>(com))
                {
                    // No longer needed to release
                    com = IntPtr.Zero;

                    // Create wrapper
                    var wrapper = typed.MarshalToManaged();
                    try
                    {
                        // Safe process
                        return(new Typed <DataType>(wrapper));
                    }
                    catch
                    {
                        // Cleanup
                        wrapper.Dispose();

                        // Forward
                        throw;
                    }
                }
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref com);
            }
        }
Example #12
0
        /// <summary>
        /// Trennt diesen Endpunkt von allen anderen.
        /// </summary>
        public void Disconnect()
        {
            // Release
            BDAEnvironment.Release(ref m_Allocator);
            BDAEnvironment.Release(ref m_Connected);

            // Release
            m_ConnectType.Dispose();
            m_ConnectType = new MediaType();

            // Reset
            m_AllocatorReadOnly = false;
            m_Connected         = IntPtr.Zero;
            m_Allocator         = null;
        }
Example #13
0
        /// <summary>
        /// Beendet die Nutzung dieser Instanz endgültig.
        /// </summary>
        public override void Dispose()
        {
            // Stop all
            Stop();

            // Forward to input pin
            using (DataManager)
                DataManager = null;

            // Forget the graph
            BDAEnvironment.Release(ref m_Graph);

            // Forward
            base.Dispose();
        }
Example #14
0
        /// <summary>
        /// Verbindet diesen Ausgang mit dem Eingang eines beliebigen Filters.
        /// </summary>
        /// <param name="receiver">Der Filter, der die erzeugten Daten verarbeiten soll.</param>
        /// <param name="mediaType">Die Art der zu verwendenden Daten.</param>
        public void Connect(TypedComIdentity <IBaseFilter> receiver, MediaType mediaType)
        {
            // Attach to the one input pin
            var to = receiver.GetSinglePin(PinDirection.Input);

            try
            {
                // Process
                Connect(to.Interface, mediaType.GetReference());
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref to);
            }
        }
Example #15
0
        /// <summary>
        /// Verbindet diesen Endpunkt mit einem anderen.
        /// </summary>
        /// <param name="connector">Ein Erzeuger.</param>
        /// <param name="mediaType">Der gewünschte Datentyp.</param>
        public void ReceiveConnection(IntPtr connector, IntPtr mediaType)
        {
            // Free
            BDAEnvironment.Release(ref m_Connected);

            // Remember
            if (connector != null)
            {
                Marshal.AddRef(connector);
            }
            m_Connected = connector;

            // Clone the media type
            m_ConnectType.Dispose();
            m_ConnectType = new MediaType(mediaType);
        }
Example #16
0
        /// <summary>
        /// Erzeugt einen neuen Filter.
        /// </summary>
        /// <returns>Der gewünschte Filter.</returns>
        public static VMR Create()
        {
            // Create
            var instance = Marshal.BindToMoniker(VMRMoniker);

            try
            {
                // Report
                return(new VMR(instance));
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref instance);
            }
        }
        /// <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>
        /// Ermittelt alle Decoder Filter, die ein bestimmtes Format unterstützen.
        /// </summary>
        /// <param name="filters">Filterbedingung für die Suche.</param>
        /// <returns>Alle zur Bedingung passenden Filter.</returns>
        private static IDeviceOrFilterInformation[] FindFilterByDecoderType(params Guid[] filters)
        {
            // Validate
            if (0 != (filters.Length % 2))
            {
                throw new ArgumentException("filters");
            }

            // Create result
            var list = new List <FilterInformation>();

            // Create the filter mapper
            var mapper = (IFilterMapper2)Activator.CreateInstance(Type.GetTypeFromCLSID(Constants.CLSID_FilterMapper2));

            try
            {
                // Lock in memory
                var fixFilter = GCHandle.Alloc(filters, GCHandleType.Pinned);
                try
                {
                    // Request enumerator
                    IEnumMoniker monikers = null;
                    mapper.EnumMatchingFilters(out monikers, 0, 1, 0x200001, 1, filters.Length / 2, fixFilter.AddrOfPinnedObject(), IntPtr.Zero, IntPtr.Zero, 0, 1, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

                    // Add all to the list using device and filter helper
                    DeviceAndFilterInformations.Cache.LoadFromEnumeration(Guid.Empty, "CLSID", list, monikers);
                }
                finally
                {
                    // Unlock memory
                    fixFilter.Free();
                }
            }
            finally
            {
                // Back to COM
                BDAEnvironment.Release(ref mapper);
            }

            // Report
            return(list.ToArray());
        }
Example #19
0
        /// <summary>
        /// Ordnet dieser Instanz einem Graphen zu.
        /// </summary>
        /// <param name="graph">Der gewünschte Graph.</param>
        /// <param name="name">Der Name des Filters im Graphen.</param>
        public void JoinFilterGraph(IFilterGraph graph, string name)
        {
            // Cleanup
            BDAEnvironment.Release(ref m_Graph);

            // Remember
            m_Name = name;

            // Disconnect request
            if (graph == null)
            {
                return;
            }

            // Remember
            m_Graph = Marshal.GetIUnknownForObject(graph);

            // Release
            if (Marshal.IsComObject(graph))
            {
                Marshal.ReleaseComObject(graph);
            }
        }
Example #20
0
 /// <summary>
 /// Gibt die Filterreferenz zu diesem Endpunkt frei.
 /// </summary>
 public void DisposeFilter()
 {
     // Free COM reference
     BDAEnvironment.Release(ref Filter);
 }
        /// <summary>
        /// Untersucht alle Endpunkte eines Filters.
        /// </summary>
        /// <param name="filter">Der zu betrachtende Filter.</param>
        /// <param name="selector">Optional eine Auswahlfunktion.</param>
        /// <param name="action">Optional eine Aktion, die pro Endpunkt ausgeführt werden soll.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Filter angegeben.</exception>
        public static void InspectAllPins(this TypedComIdentity <IBaseFilter> filter, Predicate <IPin> selector, Func <IPin, bool> action)
        {
            // Validate
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            // Attach to the instance
            using (var filterInstance = filter.MarshalToManaged())
            {
                // Attach to all pins
                var pins = filterInstance.Object.EnumPins();
                try
                {
                    // Process all
                    for (; ;)
                    {
                        using (var array = new COMArray(1))
                        {
                            // Load
                            uint count = 0;
                            if (pins.Next(1, array.Address, ref count) != 0)
                            {
                                break;
                            }

                            // Load object
                            if (count != 1)
                            {
                                continue;
                            }

                            // Load the one
                            var pin = array.GetObject <IPin>(0);
                            try
                            {
                                // Check predicate
                                if (selector != null)
                                {
                                    if (!selector(pin))
                                    {
                                        continue;
                                    }
                                }

                                // Execute
                                if (action != null)
                                {
                                    if (!action(pin))
                                    {
                                        return;
                                    }
                                }
                            }
                            finally
                            {
                                // Cleanup
                                BDAEnvironment.Release(ref pin);
                            }
                        }
                    }
                }
                finally
                {
                    // Cleanup
                    BDAEnvironment.Release(ref pins);
                }
            }
        }
Example #22
0
        /// <summary>
        /// Untersucht alle Datenformate eines Endpunktes.
        /// </summary>
        /// <param name="pin">Der zu betrachtende Endpunkt.</param>
        /// <param name="selector">Optional eine Auswahlfunktion.</param>
        /// <param name="action">Optional eine Aktion, die pro Format ausgeführt werden soll.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Endpunkt angegeben.</exception>
        public static void InspectAllMediaTypes <T>(this T pin, Predicate <MediaType> selector, Func <MediaType, bool> action) where T : IPin
        {
            // Validate
            if (pin == null)
            {
                throw new ArgumentNullException("pin");
            }

            // Attach to all pins
            var types = pin.EnumMediaTypes();

            try
            {
                // Process all
                for (; ;)
                {
                    using (var array = new COMArray(1, false))
                    {
                        // Load
                        uint count;
                        if (types.Next(1, array.Address, out count) != 0)
                        {
                            break;
                        }

                        // Load object
                        if (count != 1)
                        {
                            continue;
                        }

                        // Load the one
                        using (var type = new MediaType(array[0], false))
                        {
                            // Check predicate
                            if (selector != null)
                            {
                                if (!selector(type))
                                {
                                    continue;
                                }
                            }

                            // Execute
                            if (action != null)
                            {
                                if (!action(type))
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref types);
            }
        }
        /// <summary>
        /// Setzt die DVB-S2 Empfangsparameter.
        /// </summary>
        /// <param name="tune">Informationen zur aktuellen Auswahl der Quellgruppe.</param>
        /// <returns>Beschreibt, wie weiter vorzugehen ist.</returns>
        private static PipelineResult TuneDVBS2(DataGraph.TuneToken tune)
        {
            // Graph is starting or resetting
            var group = (tune == null) ? null : tune.SourceGroup as SatelliteGroup;

            if (group == null)
            {
                return(PipelineResult.Continue);
            }

            // Attach to tuner
            var tuner = tune.Pipeline.Graph.TunerFilter;

            if (tuner == null)
            {
                return(PipelineResult.Continue);
            }

            // Verify that grpah is created
            if (tune.Pipeline.Graph.TransportStreamAnalyser == null)
            {
                return(PipelineResult.Continue);
            }

            // Not DVB-S2
            if (!group.UsesS2Modulation)
            {
                return(PipelineResult.Continue);
            }

            // Attach to the BDA interface
            var config = tuner.GetDigitalDemodulator();

            if (config == null)
            {
                return(PipelineResult.Continue);
            }

            // Requires cleanup
            try
            {
                // Change interface
                var config2 = config as IBDADigitalDemodulator2;
                if (config2 == null)
                {
                    return(PipelineResult.Continue);
                }

                // Pilot to use
                var pilot = PilotMode.NotSet;

                // Roll-Off to use
                var rollOff = RollOff.NotDefined;
                switch (group.RollOff)
                {
                case S2RollOffs.Alpha20: rollOff = RollOff.Twenty; break;

                case S2RollOffs.Alpha25: rollOff = RollOff.TwentyFive; break;

                case S2RollOffs.Alpha35: rollOff = RollOff.ThirtyFive; break;

                default: rollOff = RollOff.NotSet; break;
                }

                // Modulation to use
                var modulation = ModulationType.NotDefined;
                switch (group.Modulation)
                {
                case SatelliteModulations.QPSK: modulation = ModulationType.NBCQPSK; break;

                case SatelliteModulations.PSK8: modulation = ModulationType.NBC8PSK; break;

                case SatelliteModulations.QAM16: modulation = ModulationType.QAM16; break;
                }

                // Update conditionally
                if (modulation != ModulationType.NotDefined)
                {
                    config2.SetModulation(ref modulation);
                }

                // Update unconditionally
                config2.SetRollOff(ref rollOff);
                config2.SetPilot(ref pilot);
            }
            finally
            {
                // Back to COM
                BDAEnvironment.Release(ref config);
            }

            // Normal
            return(PipelineResult.Continue);
        }
        /// <summary>
        /// Führt die DiSEqC Steuerung aus.
        /// </summary>
        /// <param name="token">Die aktuellen Informationen zum Wechsel der Quellgruppe.</param>
        /// <returns>Meldet, wie die weitere Abarbeitung zu erfolgen hat.</returns>
        private static PipelineResult ApplyDiSEqC(DataGraph.TuneToken token)
        {
            // Check mode
            var location = (token == null) ? null : token.GroupLocation as SatelliteLocation;

            if (location == null)
            {
                return(PipelineResult.Continue);
            }

            // Load tuner
            var tuner = token.Pipeline.Graph.TunerFilter;

            if (tuner == null)
            {
                return(PipelineResult.Continue);
            }

            // Verify that grpah is created
            if (token.Pipeline.Graph.TransportStreamAnalyser == null)
            {
                return(PipelineResult.Continue);
            }

            // Check support
            var diseqc = tuner.GetOutputControlNode <IBDADiseqCommand>(0);

            if (diseqc == null)
            {
                return(PipelineResult.Continue);
            }

            // Requires cleanup
            try
            {
                // Enable
                diseqc.Enable = true;

                // Set mode
                switch (location.LNB)
                {
                case DiSEqCLocations.BurstOff: diseqc.UseToneBurst = false; break;

                case DiSEqCLocations.BurstOn: diseqc.UseToneBurst = true; break;

                case DiSEqCLocations.DiSEqC1: diseqc.LNBSource = 1; break;

                case DiSEqCLocations.DiSEqC2: diseqc.LNBSource = 2; break;

                case DiSEqCLocations.DiSEqC3: diseqc.LNBSource = 3; break;

                case DiSEqCLocations.DiSEqC4: diseqc.LNBSource = 4; break;

                case DiSEqCLocations.None: diseqc.Enable = false; break;
                }
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref diseqc);
            }

            // Next
            return(PipelineResult.Continue);
        }
        /// <summary>
        /// Aktiviert die Auswahl einer DVB-S2 Quellgruppe.
        /// </summary>
        /// <param name="tune">Der aktuelle Auswahlvorgang.</param>
        /// <returns>Beschreibt, wie die Bearbeitung weiter fortgeführt werden soll.</returns>
        private static PipelineResult ActivateS2(DataGraph.TuneToken tune)
        {
            // Graph is starting or resetting
            var group = (tune == null) ? null : tune.SourceGroup as SatelliteGroup;

            if (group == null)
            {
                return(PipelineResult.Continue);
            }

            // Attach to tuner
            var tuner = tune.Pipeline.Graph.TunerFilter;

            if (tuner == null)
            {
                return(PipelineResult.Continue);
            }

            // Verify that grpah is created
            if (tune.Pipeline.Graph.TransportStreamAnalyser == null)
            {
                return(PipelineResult.Continue);
            }

            // Not DVB-S2
            if (!group.UsesS2Modulation)
            {
                return(PipelineResult.Continue);
            }

            // Attach to the locator of the tune request
            var locator = tune.TuneRequest.Locator;

            try
            {
                // Apply modulation
                switch (group.Modulation)
                {
                case SatelliteModulations.QPSK: locator.Modulation = (ModulationType)(ModulationType.AnalogFrequency + 5); break;

                case SatelliteModulations.PSK8: locator.Modulation = (ModulationType)(ModulationType.AnalogFrequency + 6); break;

                case SatelliteModulations.QAM16: locator.Modulation = ModulationType.QAM16; break;
                }

                // Store back
                tune.TuneRequest.Locator = locator;
            }
            finally
            {
                // Cleanup properly
                BDAEnvironment.Release(ref locator);
            }

            // Attach to the one input pin of the tuner
            using (var input = tuner.GetSinglePin(PinDirection.Input))
            {
                // Start with roll-off
                using (var propertySet = KsPropertySet.Create <RollOff>(input.Interface))
                    if (propertySet != null)
                    {
                        // Get the property and node to use
                        var roNode = KsPNode.Create(BdaTunerExtensionProperties, BDATunerExtensions.RollOff, BDANodes.Tuner);

                        // Update
                        if (propertySet.DoesSupport(roNode, PropertySetSupportedTypes.Set))
                        {
                            switch (group.RollOff)
                            {
                            case S2RollOffs.Alpha35: propertySet.Set(roNode, RollOff.Offset35); break;

                            case S2RollOffs.Alpha25: propertySet.Set(roNode, RollOff.Offset25); break;

                            case S2RollOffs.Alpha20: propertySet.Set(roNode, RollOff.Offset20); break;

                            default: propertySet.Set(roNode, RollOff.NotSet); break;
                            }
                        }
                    }

                // Continue with pilot
                using (var propertySet = KsPropertySet.Create <Pilot>(input.Interface))
                    if (propertySet != null)
                    {
                        // Get the property and node to use
                        var piNode = KsPNode.Create(BdaTunerExtensionProperties, BDATunerExtensions.Pilot, BDANodes.Tuner);

                        // Update
                        if (propertySet.DoesSupport(piNode, PropertySetSupportedTypes.Set))
                        {
                            propertySet.Set(piNode, Pilot.NotSet);
                        }
                    }
            }

            // Normal
            return(PipelineResult.Continue);
        }
Example #26
0
        /// <summary>
        /// Führt die DiSEqC Steuerung aus.
        /// </summary>
        /// <param name="token">Die aktuellen Informationen zum Wechsel der Quellgruppe.</param>
        /// <returns>Meldet, wie die weitere Abarbeitung zu erfolgen hat.</returns>
        private static PipelineResult ApplyDiSEqC(DataGraph.TuneToken token)
        {
            // Check mode
            var location = (token == null) ? null : token.GroupLocation as SatelliteLocation;

            if (location == null)
            {
                return(PipelineResult.Continue);
            }

            // Attach to capture
            var capture = token.Pipeline.Graph.CaptureFilter;

            if (capture == null)
            {
                return(PipelineResult.Continue);
            }

            // Verify that grpah is created
            if (token.Pipeline.Graph.TransportStreamAnalyser == null)
            {
                return(PipelineResult.Continue);
            }

            // Initial
            uint positionOption;

            switch (location.LNB)
            {
            case DiSEqCLocations.DiSEqC1: positionOption = 0x0000; break;

            case DiSEqCLocations.DiSEqC2: positionOption = 0x0001; break;

            case DiSEqCLocations.DiSEqC3: positionOption = 0x0100; break;

            case DiSEqCLocations.DiSEqC4: positionOption = 0x0101; break;

            default: positionOption = uint.MaxValue; break;
            }

            // Request interface
            var filter = capture.GetFrequencyFilter();

            if (filter != null)
            {
                // Do it the more or less modern way
                try
                {
                    // Load
                    filter.Range = positionOption;
                }
                finally
                {
                    // Cleanup
                    BDAEnvironment.Release(ref filter);
                }
            }
            else
            {
                // Attach to the tuning space
                var space = token.TuneRequest.TuningSpace;
                try
                {
                    // Store
                    ((IDVBSTuningSpace)space).InputRange = positionOption.ToString();
                }
                finally
                {
                    // Cleanup
                    BDAEnvironment.Release(ref space);
                }
            }

            // Next
            return(PipelineResult.Continue);
        }
Example #27
0
        /// <summary>
        /// Wertet alle Filter in einem Graphen aus.
        /// </summary>
        /// <typeparam name="T">Konkret verwendete Schnittstelle.</typeparam>
        /// <param name="graph">Der zu untersuchende Graph.</param>
        /// <param name="action">Wird für jeden gefundenen Filter aktiviert.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Graph angegeben.</exception>
        public static void InspectFilters <T>(this T graph, Func <IBaseFilter, bool> action) where T : IFilterGraph
        {
            // Validate
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }

            // Get enumerator
            var filters = graph.EnumFilters();

            if (filters == null)
            {
                return;
            }

            // List to process
            var process = new List <IBaseFilter>();

            try
            {
                // Process all
                for (; ;)
                {
                    using (var filterArray = new COMArray(1))
                    {
                        // Load
                        uint n;
                        if (filters.Next(1, filterArray.Address, out n) != 0)
                        {
                            break;
                        }
                        if (n != 1)
                        {
                            break;
                        }

                        // Load
                        process.Add(filterArray.GetObject <IBaseFilter>(0));
                    }
                }
            }
            catch
            {
                // Disable action
                action = null;

                // Forward
                throw;
            }
            finally
            {
                // Cleanup enumeration
                BDAEnvironment.Release(ref filters);

                // Safe process
                try
                {
                    // Test all
                    if (action != null)
                    {
                        foreach (var filter in process)
                        {
                            if (!action(filter))
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    // Cleanup collected filters
                    foreach (var filter in process)
                    {
                        if (Marshal.IsComObject(filter))
                        {
                            Marshal.ReleaseComObject(filter);
                        }
                    }
                }
            }
        }
        /// <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;
            }
        }
Example #29
0
        /// <summary>
        /// Erzeugt den zugehörigen Filter.
        /// </summary>
        /// <returns>Der gewünschte Filter.</returns>
        /// <exception cref="NotSupportedException">Der angeforderte Filter existiert.</exception>
        public TypedComIdentity <IBaseFilter> CreateFilter()
        {
            // Create system device enumerator
            var devEnum = (ICreateDevEnum)Activator.CreateInstance(System.Type.GetTypeFromCLSID(BDAEnvironment.SystemDeviceEnumeratorClassIdentifier));

            try
            {
                // Helper
                var category = Category;

                // Get the enumerator
                IEnumMoniker monikers;
                if (devEnum.CreateClassEnumerator(ref category, out monikers, 0) >= 0)
                {
                    if (monikers != null)
                    {
                        try
                        {
                            // Process all
                            for (; ;)
                            {
                                using (var array = new COMArray(1))
                                {
                                    // Load
                                    uint count;
                                    if (monikers.Next(1, array.Address, out count) != 0)
                                    {
                                        break;
                                    }
                                    if (count != 1)
                                    {
                                        break;
                                    }

                                    // Load object
                                    var moniker = array.GetObject <IMoniker>(0);
                                    try
                                    {
                                        // Check name
                                        if (string.Equals(Moniker, moniker.ReadProperty("DevicePath")))
                                        {
                                            // Create the instance
                                            var iid    = new Guid("56a86895-0ad4-11ce-b03a-0020af0ba770");
                                            var filter = moniker.BindToObject(null, null, ref iid);

                                            // Report safely
                                            try
                                            {
                                                // Construct
                                                return(ComIdentity.Create((IBaseFilter)filter));
                                            }
                                            catch
                                            {
                                                // Cleanup
                                                BDAEnvironment.Release(ref filter);

                                                // Forward
                                                throw;
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        // Release
                                        BDAEnvironment.Release(ref moniker);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            // Cleanup
                            BDAEnvironment.Release(ref monikers);
                        }
                    }
                }
            }
            finally
            {
                // Back to COM
                BDAEnvironment.Release(ref devEnum);
            }

            // Not found
            throw new NotSupportedException(string.Format(Properties.Resources.Exception_BadFilter, this));
        }