private void processExtendedTextTable(Collection <Mpeg2Section> sections)
        {
            foreach (Mpeg2Section section in sections)
            {
                if (RunParameters.Instance.DebugIDs.Contains("EXTENDEDTEXTTABLE"))
                {
                    Logger.Instance.Dump("PSIP Extended Text Table", section.Data, section.Data.Length);
                }

                try
                {
                    Mpeg2ExtendedHeader mpeg2Header = new Mpeg2ExtendedHeader();
                    mpeg2Header.Process(section.Data);
                    if (mpeg2Header.Current)
                    {
                        ExtendedTextTable extendedTextTable = new ExtendedTextTable();
                        extendedTextTable.Process(section.Data, mpeg2Header);
                        extendedTextTable.LogMessage();
                    }
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Logger.Instance.Write("<e> PSIP error: " + e.Message);
                }
            }
        }
        private void processEvent(int frequency, int sourceID, EventInformationTableEntry eventEntry)
        {
            VirtualChannel channel = VirtualChannelTable.FindChannel(frequency, sourceID);

            if (channel == null)
            {
                return;
            }

            EPGEntry epgEntry = new EPGEntry();

            epgEntry.EventID = eventEntry.EventID;

            if (eventEntry.EventName != null)
            {
                epgEntry.EventName = eventEntry.EventName.ToString().Replace("\0", "");
            }
            else
            {
                epgEntry.EventName = "No Event Name";
            }

            if (eventEntry.ETMLocation == 1 || eventEntry.ETMLocation == 2)
            {
                ExtendedTextTableEntry textEntry = ExtendedTextTable.FindEntry(sourceID, eventEntry.EventID);
                if (textEntry != null)
                {
                    epgEntry.ShortDescription = textEntry.Text.ToString().Replace("\0", "");
                }
            }

            epgEntry.StartTime            = Utils.RoundTime(TimeOffsetEntry.GetAdjustedTime(eventEntry.StartTime));
            epgEntry.Duration             = Utils.RoundTime(eventEntry.Duration);
            epgEntry.EventCategory        = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, eventEntry);
            epgEntry.ParentalRating       = eventEntry.ParentalRating;
            epgEntry.ParentalRatingSystem = "VCHIP";
            epgEntry.AudioQuality         = eventEntry.AudioQuality;
            epgEntry.EPGSource            = EPGSource.PSIP;

            channel.AddEPGEntry(epgEntry);
        }
Esempio n. 3
0
        private void processExtendedTextTable(Collection<Mpeg2Section> sections)
        {
            foreach (Mpeg2Section section in sections)
            {
                if (RunParameters.Instance.DebugIDs.Contains("EXTENDEDTEXTTABLE"))
                    Logger.Instance.Dump("PSIP Extended Text Table", section.Data, section.Data.Length);

                try
                {
                    Mpeg2ExtendedHeader mpeg2Header = new Mpeg2ExtendedHeader();
                    mpeg2Header.Process(section.Data);
                    if (mpeg2Header.Current)
                    {
                        ExtendedTextTable extendedTextTable = new ExtendedTextTable();
                        extendedTextTable.Process(section.Data, mpeg2Header);
                        extendedTextTable.LogMessage();
                    }
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Logger.Instance.Write("<e> PSIP error: " + e.Message);
                }
            }
        }
        /// <summary>
        /// Create the EPG entries.
        /// </summary>
        public override void FinishFrequency()
        {
            if (RunParameters.Instance.DebugIDs.Contains("LOGPSIPEXTENDEDTEXT"))
            {
                ExtendedTextTable.LogEntries();
            }

            AtscPsipProgramCategory.LogCategoryUsage();

            if (VirtualChannelTable.Channels.Count == 0)
            {
                return;
            }

            Logger titleLogger       = null;
            Logger descriptionLogger = null;

            if (RunParameters.Instance.DebugIDs.Contains("LOGTITLES"))
            {
                titleLogger = new Logger("EPG Titles.log");
            }
            if (RunParameters.Instance.DebugIDs.Contains("LOGDESCRIPTIONS"))
            {
                descriptionLogger = new Logger("EPG Descriptions.log");
            }

            foreach (VirtualChannel channel in VirtualChannelTable.Channels)
            {
                TVStation station = TVStation.FindStation(channel.CollectionFrequency, channel.MajorChannelNumber, channel.MinorChannelNumber);
                if (station == null)
                {
                    station = new TVStation(channel.ShortName);
                    station.OriginalNetworkID = channel.CollectionFrequency;
                    station.TransportStreamID = channel.MajorChannelNumber;
                    station.ServiceID         = channel.MinorChannelNumber;
                    station.ChannelID         = channel.MajorChannelNumber + ":" + channel.MinorChannelNumber + ":" + channel.ShortName;
                    TVStation.AddStation(station);
                }

                station.Name = channel.ShortName;

                if (station.LogicalChannelNumber == -1)
                {
                    station.LogicalChannelNumber = (channel.MajorChannelNumber * 100) + channel.MinorChannelNumber;
                }

                station.MinorChannelNumber = channel.MinorChannelNumber;

                if (station.EPGCollection.Count == 0)
                {
                    foreach (EPGEntry epgEntry in channel.EPGCollection)
                    {
                        station.EPGCollection.Add(epgEntry);

                        if (titleLogger != null)
                        {
                            titleLogger.Write(epgEntry.ServiceID + " " +
                                              epgEntry.StartTime.ToShortDateString() + " " +
                                              epgEntry.StartTime.ToString("HH:mm") + " - " +
                                              epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " +
                                              epgEntry.EventName);
                        }

                        if (descriptionLogger != null && epgEntry.ShortDescription != null)
                        {
                            descriptionLogger.Write(epgEntry.ServiceID + " " +
                                                    " Evt ID " + epgEntry.EventID +
                                                    epgEntry.StartTime.ToShortDateString() + " " +
                                                    epgEntry.StartTime.ToString("HH:mm") + " - " +
                                                    epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " +
                                                    epgEntry.ShortDescription);
                        }
                    }
                }
            }
        }
        private void getExtendedTextData(ISampleDataProvider dataProvider, BackgroundWorker worker)
        {
            Logger.Instance.Write("Collecting Extended Text data", false, true);
            ExtendedTextTable.Clear();

            int[] extendedTextPids = masterGuideTable.GetETTPids();
            if (extendedTextPids.Length == 0)
            {
                Logger.Instance.Write("", true, false);
                Logger.Instance.Write("No Extended Text Data PID's in Master Guide Table");
                return;
            }

            dataProvider.ChangePidMapping(masterGuideTable.GetETTPids());

            guideReader = new TSStreamReader(0xcc, 2000, dataProvider.BufferAddress);
            guideReader.Run();

            int  lastCount = 0;
            int  repeats   = 0;
            bool done      = false;

            while (!done)
            {
                if (worker.CancellationPending)
                {
                    return;
                }

                Thread.Sleep(2000);
                Logger.Instance.Write(".", false, false);

                Collection <Mpeg2Section> sections = new Collection <Mpeg2Section>();

                guideReader.Lock("LoadMessages");
                if (guideReader.Sections.Count != 0)
                {
                    foreach (Mpeg2Section section in guideReader.Sections)
                    {
                        sections.Add(section);
                    }
                    guideReader.Sections.Clear();
                }
                guideReader.Release("LoadMessages");

                if (sections.Count != 0)
                {
                    processExtendedTextTable(sections);
                }

                if (ExtendedTextTable.TextEntries.Count == lastCount)
                {
                    repeats++;
                    done = (repeats == RunParameters.Instance.Repeats);
                }
                else
                {
                    repeats = 0;
                }

                lastCount = ExtendedTextTable.TextEntries.Count;
            }

            Logger.Instance.Write("", true, false);
            Logger.Instance.Write("Stopping reader");
            guideReader.Stop();

            Logger.Instance.Write("Extended Text Data: Entry count: " + ExtendedTextTable.TextEntries.Count + " buffer space used: " + dataProvider.BufferSpaceUsed);
        }