internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("GenPix", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("GenPix DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (modulationType)
            {
            case ModulationType.ModQpsk:
                modulationType = ModulationType.Mod8Vsb;
                break;

            case ModulationType.Mod8Psk:
                modulationType = ModulationType.Mod8Vsb;
                break;

            case ModulationType.Mod16Apsk:
                modulationType = ModulationType.Mod16Vsb;
                break;

            case ModulationType.Mod32Apsk:
                modulationType = ModulationType.ModOqpsk;
                break;

            default:
                break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("GenPix DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("GenPix DVB-S2 handler: Modulation type changed to " + modulationType);
                }
            }
            else
            {
                Logger.Instance.Write("GenPix DVB-S2 handler: Modulation type not changed");
            }

            return(true);
        }
示例#2
0
        protected IBDA_DigitalDemodulator FindDemodulator(string identifier, IBaseFilter tunerFilter)
        {
            IBDA_Topology topology = tunerFilter as IBDA_Topology;

            if (topology == null)
            {
                return(null);
            }

            int nodeTypeCount = 0;

            int[] nodeTypes = new int[10];

            int reply = topology.GetNodeTypes(out nodeTypeCount, 10, nodeTypes);

            DsError.ThrowExceptionForHR(reply);

            for (int nodeTypeIndex = 0; nodeTypeIndex < nodeTypeCount; nodeTypeIndex++)
            {
                int    interfaceCount;
                Guid[] interfaces = new Guid[32];
                reply = topology.GetNodeInterfaces(nodeTypes[nodeTypeIndex], out interfaceCount, 32, interfaces);
                DsError.ThrowExceptionForHR(reply);
            }

            for (int nodeTypeIndex = 0; nodeTypeIndex < nodeTypeCount; nodeTypeIndex++)
            {
                int    interfaceCount;
                Guid[] interfaces = new Guid[32];
                reply = topology.GetNodeInterfaces(nodeTypes[nodeTypeIndex], out interfaceCount, 32, interfaces);
                DsError.ThrowExceptionForHR(reply);

                for (int searchIndex = 0; searchIndex < interfaceCount; searchIndex++)
                {
                    if (interfaces[searchIndex] == typeof(IBDA_DigitalDemodulator).GUID)
                    {
                        object controlNode;
                        reply = topology.GetControlNode(0, 1, nodeTypes[nodeTypeIndex], out controlNode);
                        DsError.ThrowExceptionForHR(reply);

                        IBDA_DigitalDemodulator demodulator = controlNode as IBDA_DigitalDemodulator;
                        if (demodulator == null)
                        {
                            Logger.Instance.Write(identifier + " DVB-S2 handler: Can't get demodulator: cast of control node failed");
                        }
                        else
                        {
                            Logger.Instance.Write(identifier + " DVB-S2 handler: Demodulator interface located");
                            return(demodulator);
                        }
                    }
                }
            }

            Logger.Instance.Write(identifier + " DVB-S2 handler: Failed to find demodulator interface");

            return(null);
        }
        internal override bool ClearDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("Hauppauge", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = tuningSpec.NativeModulation;

            reply = demodulator.put_ModulationType(ref modulationType);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                return(false);
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type set to " + modulationType);
            }

            IntPtr commandBuffer  = Marshal.AllocCoTaskMem(1024);
            IntPtr instanceBuffer = Marshal.AllocCoTaskMem(1024);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            Marshal.WriteInt32(commandBuffer, (int)DirectShowAPI.Pilot.NotSet);
            reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_PILOT, instanceBuffer, 32, commandBuffer, 4);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Pilot set to off");
            }

            return(reply == 0);
        }
示例#4
0
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("DigitalEverywhere", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (tuningSpec.Modulation)
            {
            case Modulation.QPSK:
                modulationType = ModulationType.ModNbcQpsk;
                break;

            case Modulation.PSK8:
                modulationType = ModulationType.ModNbc8Psk;
                break;

            default:
                break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Modulation type changed to " + modulationType);
                }
            }
            else
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Modulation type not changed");
            }

            BinaryConvolutionCodeRate oldCodeRate;

            reply = demodulator.get_InnerFECRate(out oldCodeRate);
            if (reply != 0)
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Get FEC Rate failed error code 0x" + reply.ToString("X"));
                return(false);
            }

            SatelliteFrequency satelliteFrequency = tuningSpec.Frequency as SatelliteFrequency;

            BinaryConvolutionCodeRate newCodeRate = oldCodeRate;

            if (satelliteFrequency.Pilot == DomainObjects.Pilot.Off)
            {
                newCodeRate += 64;
            }
            else
            {
                if (satelliteFrequency.Pilot == DomainObjects.Pilot.On)
                {
                    newCodeRate += 128;
                }
            }

            switch (satelliteFrequency.RollOff)
            {
            case DomainObjects.RollOff.RollOff20:
                newCodeRate += 16;
                break;

            case DomainObjects.RollOff.RollOff25:
                newCodeRate += 32;
                break;

            case DomainObjects.RollOff.RollOff35:
                newCodeRate += 48;
                break;

            default:
                break;
            }

            if (oldCodeRate != newCodeRate)
            {
                reply = demodulator.put_InnerFECRate(newCodeRate);
                if (reply != 0)
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Set FEC Rate failed error code 0x" + reply.ToString("X"));
                    return(false);
                }

                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: FEC Rate changed from " + oldCodeRate + " to " + newCodeRate);
            }

            return(true);
        }
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("Hauppauge", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (tuningSpec.Modulation)
            {
            case Modulation.QPSK:
                BinaryConvolutionCodeRate codeRate;
                reply = demodulator.get_InnerFECRate(out codeRate);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Get FEC rate failed error code 0x" + reply.ToString("X"));
                    return(false);
                }

                if (codeRate == BinaryConvolutionCodeRate.Rate9_10)
                {
                    modulationType = ModulationType.Mod32Qam;
                }
                else
                {
                    if (codeRate == BinaryConvolutionCodeRate.Rate8_9)
                    {
                        modulationType = ModulationType.Mod16Qam;
                    }
                    else
                    {
                        modulationType = ModulationType.ModBpsk;
                    }
                }
                break;

            case Modulation.PSK8:
                modulationType = ModulationType.ModNbc8Psk;
                break;

            default:
                break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type changed to " + modulationType);
                }
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type not changed");
            }

            IntPtr commandBuffer  = Marshal.AllocCoTaskMem(1024);
            IntPtr instanceBuffer = Marshal.AllocCoTaskMem(1024);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            string setting;

            if (frequency.SymbolRate != 30000)
            {
                Marshal.WriteInt32(commandBuffer, (int)DsUtils.GetNativePilot(frequency.Pilot));
                setting = frequency.Pilot.ToString();
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Setting pilot to off for symbol rate of 30000");
                Marshal.WriteInt32(commandBuffer, (int)DirectShowAPI.Pilot.Off);
                setting = "Off";
            }
            reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_PILOT, instanceBuffer, 32, commandBuffer, 4);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
                return(false);
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Pilot set to " + setting);

                Marshal.WriteInt32(commandBuffer, (int)DsUtils.GetNativeRollOff(frequency.RollOff));
                reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_ROLL_OFF, instanceBuffer, 32, commandBuffer, 4);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Rolloff command failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Rolloff set to " + frequency.RollOff);
                }
            }

            return(true);
        }
        private void BuildGraph()
        {
            int hr = 0;

            graphBuilder = (IFilterGraph2) new FilterGraph();
            rot          = new DsROTEntry(graphBuilder);

            ICaptureGraphBuilder2 capBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            capBuilder.SetFiltergraph(graphBuilder);

            // Get the BDA network provider specific for this given network type
            networkProvider = BDAUtils.GetNetworkProvider(networkType);

            hr = graphBuilder.AddFilter(networkProvider, "BDA Network Provider");
            DsError.ThrowExceptionForHR(hr);

            tuner = (ITuner)networkProvider;

            // Get a tuning space for this network type
            tuningSpace = BDAUtils.GetTuningSpace(networkType);

            hr = tuner.put_TuningSpace(tuningSpace);
            DsError.ThrowExceptionForHR(hr);

            // Create a tune request from this tuning space
            tuneRequest = BDAUtils.CreateTuneRequest(tuningSpace);

            // Is it okay ?
            hr = tuner.Validate(tuneRequest);
            if (hr == 0)
            {
                // Set it
                hr = tuner.put_TuneRequest(tuneRequest);
                DsError.ThrowExceptionForHR(hr);

                // found a BDA Tuner and a BDA Capture that can connect to this network provider
                BDAUtils.AddBDATunerAndDemodulatorToGraph(graphBuilder, networkProvider, out bdaTuner, out bdaCapture);

                if ((bdaTuner != null) && (bdaCapture != null))
                {
                    // Create and add the mpeg2 demux
                    mpeg2Demux = (IBaseFilter) new MPEG2Demultiplexer();

                    hr = graphBuilder.AddFilter(mpeg2Demux, "MPEG2 Demultiplexer");
                    DsError.ThrowExceptionForHR(hr);

                    // connect it to the BDA Capture
                    hr = capBuilder.RenderStream(null, null, bdaCapture, null, mpeg2Demux);
                    DsError.ThrowExceptionForHR(hr);

                    // Add the two mpeg2 transport stream helper filters
                    BDAUtils.AddTransportStreamFiltersToGraph(graphBuilder, out bdaTIF, out bdaSecTab);

                    if ((bdaTIF != null) && (bdaSecTab != null))
                    {
                        // Render all the output pins of the demux (missing filters are added)
                        for (int i = 0; i < 5; i++)
                        {
                            IPin pin = DsFindPin.ByDirection(mpeg2Demux, PinDirection.Output, i);

                            hr = graphBuilder.Render(pin);
                            Marshal.ReleaseComObject(pin);
                        }
                    }

                    IBDA_Topology topo      = (IBDA_Topology)bdaTuner;
                    int[]         nodeTypes = new int[10];
                    int           nodeTypesCount;

                    // Get all nodes in the BDA Tuner
                    hr = topo.GetNodeTypes(out nodeTypesCount, nodeTypes.Length, nodeTypes);
                    DsError.ThrowExceptionForHR(hr);

                    // For each nodes types
                    for (int i = 0; i < nodeTypesCount; i++)
                    {
                        Guid[] nodeGuid = new Guid[10];
                        int    nodeGuidCount;

                        // Get its exposed interfaces
                        hr = topo.GetNodeInterfaces(nodeTypes[i], out nodeGuidCount, nodeGuid.Length, nodeGuid);
                        DsError.ThrowExceptionForHR(hr);

                        // For each exposed interfaces
                        for (int j = 0; j < nodeGuidCount; j++)
                        {
                            Debug.WriteLine(string.Format("node {0}/{1} : {2}", i, j, nodeGuid[j]));
                            Console.WriteLine(string.Format("node {0}/{1} : {2}", i, j, nodeGuid[j]));

                            // Is IBDA_AutoDemodulate supported by this node ?
                            if (nodeGuid[j] == typeof(IBDA_DigitalDemodulator).GUID)
                            {
                                // Yes, retrieve this node
                                object ctrlNode;
                                hr = topo.GetControlNode(0, 1, nodeTypes[i], out ctrlNode);
                                DsError.ThrowExceptionForHR(hr);

                                // Do the cast (it should not fail)
                                digitalDemux = ctrlNode as IBDA_DigitalDemodulator;

                                // Exit the for j loop if found a SignalStatistics object
                                if (digitalDemux != null)
                                {
                                    break;
                                }
                            }
                        }

                        // If already found a SignalStatistics object, exit the for i loop
                        if (digitalDemux != null)
                        {
                            break;
                        }
                    }
                }
            }
        }