//////////////////////////////////////////////////////////////////////////////////
// //
// Copyright © 2005-2020 nzsjb //
// //
// This Program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2, or (at your option) //
// any later version. //
// //
// This Program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with GNU Make; see the file COPYING. If not, write to //
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. //
// http://www.gnu.org/copyleft/gpl.html //
// //
//////////////////////////////////////////////////////////////////////////////////
using System;
using DomainObjects;
namespace DVBServices
{
///
/// The class that describes an Open TV Title section.
///
public class OpenTVTitleSection
{
///
/// Get the section number.
///
public int SectionNumber { get { return (sectionNumber); } }
///
/// Get the section number.
///
public int LastSectionNumber { get { return (lastSectionNumber); } }
///
/// Get the title header.
///
public OpenTVTitleHeader TitleHeader { get { return (titleHeader); } }
private int sectionNumber;
private int lastSectionNumber;
private OpenTVTitleHeader titleHeader;
private int lastIndex = -1;
///
/// Initialize a new instance of the OpenTVTitleSection class.
///
internal OpenTVTitleSection() { }
///
/// Parse the section.
///
/// The MPEG2 section containing the section.
/// The MPEG2 header that preceedes the section.
/// The PID containing the section.
/// The table ID containing the section.
internal void Process(byte[] byteData, Mpeg2ExtendedHeader mpeg2Header, int pid, int tid)
{
lastIndex = mpeg2Header.Index;
sectionNumber = mpeg2Header.SectionNumber;
lastSectionNumber = mpeg2Header.LastSectionNumber;
titleHeader = new OpenTVTitleHeader();
titleHeader.Process(byteData, lastIndex, mpeg2Header, pid, tid);
}
///
/// Log the section fields.
///
public void LogMessage()
{
if (Logger.ProtocolLogger == null)
return;
titleHeader.LogMessage();
}
///
/// Process an MPEG2 section from the Open TV Title table.
///
/// The MPEG2 section.
/// The PID containing the section.
/// The table ID containing the section.
/// An Open TV Title Section instance or null if a section is not created.
public static OpenTVTitleSection ProcessOpenTVTitleTable(byte[] byteData, int pid, int table)
{
Mpeg2ExtendedHeader mpeg2Header = new Mpeg2ExtendedHeader();
try
{
mpeg2Header.Process(byteData);
if (mpeg2Header.Current)
{
OpenTVTitleSection openTVTitleSection = new OpenTVTitleSection();
openTVTitleSection.Process(byteData, mpeg2Header, pid, table);
openTVTitleSection.LogMessage();
return (openTVTitleSection);
}
else
return (null);
}
catch (ArgumentOutOfRangeException e)
{
Logger.Instance.Write(" Error processing Title Section: " + e.Message);
if (DebugEntry.IsDefined(DebugName.TitleSection))
{
Logger.Instance.Write(e.Message);
Logger.Instance.Write(e.StackTrace);
Logger.Instance.Dump("Title Section", byteData, byteData.Length);
}
return (null);
}
}
}
}