/// <summary>
        /// Wechselt die Quellgruppe.
        /// </summary>
        /// <param name="token">Die Informationen zur neuen Quellgruppe.</param>
        /// <returns>Meldet, wie die Bearbeitung fortgesetzt werden soll.</returns>
        private PipelineResult SetTuneRequest(TuneToken token)
        {
            // Ignore termination
            if (token == null)
            {
                return(PipelineResult.Continue);
            }

            // Connect the request to the network provider
            using (var provider = NetworkProvider.MarshalToManaged())
                ((ITuner)provider.Object).TuneRequest = token.TuneRequest;

            // Now run post processings
            return(PipelineResult.Continue);
        }
예제 #2
0
        /// <summary>
        /// Sendet eine leere Anfrage zum Wechsel der Quellgruppe. Diese kann von allen Aktionen
        /// verwendet werden, um interne Zustände zu (re-)initialisieren.
        /// </summary>
        /// <param name="disableDecryptionReset">Gesetzt, um die Neuinitialisierung der Entschlüsselung
        /// zu deaktivieren.</param>
        private void SendEmptyTuneRequest(bool disableDecryptionReset = false)
        {
            // Process
            using (var tune = TuneToken.Create(TunePipeline, null, null))
                tune.Execute();
            if (!disableDecryptionReset)
            {
                using (var crypt = DecryptToken.Create(DecryptionPipeline, null))
                    crypt.Execute();
            }
            using (var sig = SignalToken.Create(SignalPipeline))
                sig.Execute();

            // Reset
            m_currentDecryption = s_NoSources;
        }
예제 #3
0
        /// <summary>
        /// Wählt eine neue Quellgruppe aus.
        /// </summary>
        /// <param name="location">Der Ursprung, über den die Quellgruppe empfangen wird.</param>
        /// <param name="group">Die gewünschte Quellgruppe.</param>
        /// <exception cref="NotSupportedException">Der Graph wurde noch nicht erzeugt.</exception>
        public void Tune(GroupLocation location, SourceGroup group)
        {
            // Validate
            if (NetworkProvider == null)
            {
                throw new NotSupportedException(Properties.Resources.Exception_NotStarted);
            }

            // PAT wait configuration - will use 1/10sec per retry
            var patRetries   = Configuration.MinimumPATCountWaitTime;
            var patsExpected = Configuration.MinimumPATCount;

            // Attach to helper
            var analyser = TransportStreamAnalyser;
            var manager  = (analyser == null) ? null : analyser.DataManager;
            var parser   = (manager == null) ? null : manager.TSParser;

            // May want to retry at least four times
            for (var outerRetry = 4; outerRetry-- > 0; patsExpected += 5, patRetries += 25)
            {
                // Always stop raw dump
                if (manager != null)
                {
                    manager.StopDump();
                }

                // Report
                if (BDASettings.BDATraceSwitch.Enabled)
                {
                    Trace.WriteLine(string.Format(Properties.Resources.Trace_TuneStart, location, group), BDASettings.BDATraceSwitch.DisplayName);
                }

                // Route request through the current pipeline
                using (var tune = TuneToken.Create(TunePipeline, location, group))
                    tune.Execute();

                // Not yet up
                if (analyser == null)
                {
                    return;
                }

                // Attach to statistics interface
                var statistics = TunerFilter.GetSignalStatistics();
                if (statistics != null)
                {
                    try
                    {
                        // Set counter
                        var tuneRetry = 10;

                        // Wait
                        for (; tuneRetry-- > 0; Thread.Sleep(100))
                        {
                            // Load the signal information
                            var locked = statistics.SignalLocked;
                            if (locked != 0)
                            {
                                break;
                            }
                        }

                        // Report
                        if (BDASettings.BDATraceSwitch.Enabled)
                        {
                            Trace.WriteLine(string.Format(Properties.Resources.Trace_Lock, 10 - tuneRetry, tuneRetry, BDASettings.FastTune), BDASettings.BDATraceSwitch.DisplayName);
                        }

                        // Final check
                        if (BDASettings.FastTune)
                        {
                            if (statistics.SignalLocked == 0)
                            {
                                return;
                            }
                        }
                    }
                    catch
                    {
                        // Just ignore any error
                    }
                    finally
                    {
                        // Back to COM
                        BDAEnvironment.Release(ref statistics);
                    }
                }

                // Check for dump
                StartDump();

                // Reset PAT detection
                parser.RestartPATCounter();

                // Request the number of bytes currently processed
                var bytes = parser.BytesReceived;
                var limit = patsExpected;
                var retry = patRetries;

                // Wait a bit
                for (; (parser.ValidPATCount < limit) && (retry-- > 0);)
                {
                    Thread.Sleep(100);
                }

                // Report
                if (BDASettings.BDATraceSwitch.Enabled)
                {
                    Trace.WriteLine(string.Format(Properties.Resources.Trace_StreamOk, patRetries - retry, retry, parser.ValidPATCount, parser.BytesReceived - bytes), BDASettings.BDATraceSwitch.DisplayName);
                }

                // Disable retry if PATs are received
                if (parser.ValidPATCount >= limit)
                {
                    break;
                }

                // Disable retry if no data is on the transponder
                if (bytes == parser.BytesReceived)
                {
                    if (outerRetry != 3)
                    {
                        break;
                    }
                }

                // Report for debugging purposes
                if (BDASettings.BDATraceSwitch.Enabled)
                {
                    Trace.WriteLine(Properties.Resources.Trace_TuneFailed, BDASettings.BDATraceSwitch.DisplayName);
                }

                // Inform all helpers on reset
                SendEmptyTuneRequest(DisableCIResetOnTuneFailure);
            }
        }