//////////////////////////////////////////////////////////////////////////////////
// //
// 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 System.Collections.ObjectModel;
using DomainObjects;
namespace DVBServices
{
///
/// The class that describes Open TV summary data.
///
public class OpenTVSummaryData
{
///
/// Get the event identification.
///
public int EventID { get { return (eventID); } }
///
/// Get the short description of the event.
///
public string ShortDescription
{
get
{
OpenTVShortDescriptionRecord record = (OpenTVShortDescriptionRecord)getRecord(OpenTVShortDescriptionRecord.TagValue);
if (record != null)
return (record.Description);
else
return null;
}
}
///
/// Get the raw bytes of short description of the event.
///
public byte[] ShortDescriptionBytes
{
get
{
OpenTVShortDescriptionRecord record = (OpenTVShortDescriptionRecord)getRecord(OpenTVShortDescriptionRecord.TagValue);
if (record != null)
return (record.DescriptionBytes);
else
return (new byte[] { 0x00 });
}
}
///
/// Get the extended description of the event.
///
public string ExtendedDescription
{
get
{
OpenTVExtendedDescriptionRecord record = (OpenTVExtendedDescriptionRecord)getRecord(OpenTVExtendedDescriptionRecord.TagValue);
if (record != null)
return (record.Description);
else
return (null);
}
}
///
/// Get the series link of the event.
///
public int SeriesLink
{
get
{
OpenTVSeriesLinkRecord record = (OpenTVSeriesLinkRecord)getRecord(OpenTVSeriesLinkRecord.TagValue);
if (record != null)
return (record.SeriesLink);
else
return (-1);
}
}
///
/// Get the collection of records for this summary section.
///
internal Collection Records
{
get
{
if (records == null)
records = new Collection();
return (records);
}
}
///
/// Get the collection of undefined records for this summary section.
///
internal Collection UndefinedRecords
{
get
{
if (records == null)
return (null);
Collection undefinedRecords = new Collection();
foreach (OpenTVRecordBase record in records)
{
if (record.IsUndefined)
undefinedRecords.Add(record);
}
return (undefinedRecords);
}
}
///
/// Get the index of the next byte in the MPEG2 section following the summary data.
///
///
/// The summary data has not been processed.
///
public int Index
{
get
{
if (lastIndex == -1)
throw (new InvalidOperationException("OpenTVSummaryData: Index requested before block processed"));
return (lastIndex);
}
}
private int eventID;
private int length;
private Collection records;
private int lastIndex = -1;
///
/// Initialize a new instance of the OpenTVSummaryData class.
///
public OpenTVSummaryData() { }
///
/// Parse the summary data.
///
/// The MPEG2 section containing the summary data.
/// Index of the first byte of the summary data in the MPEG2 section.
/// The base date for the program events.
internal void Process(byte[] byteData, int index, DateTime baseDate)
{
lastIndex = index;
try
{
eventID = Utils.Convert2BytesToInt(byteData, lastIndex);
lastIndex += 2;
length = ((byteData[lastIndex] & 0x0f) * 256) + byteData[lastIndex + 1];
lastIndex += 2;
int recordLength = length;
while (recordLength != 0)
{
OpenTVRecordBase record = OpenTVRecordBase.Instance(byteData, lastIndex);
Records.Add(record);
lastIndex += record.TotalLength;
recordLength -= record.TotalLength;
}
Validate();
}
catch (IndexOutOfRangeException)
{
throw (new ArgumentOutOfRangeException("The Open TV Summary Data message is short"));
}
}
///
/// Validate the summary data fields.
///
///
/// A summary data field is not valid.
///
public void Validate() { }
///
/// Log the summary data fields.
///
public void LogMessage()
{
if (Logger.ProtocolLogger == null)
return;
Logger.ProtocolLogger.Write(Logger.ProtocolIndent + "OPENTV SUMMARY DATA: Event ID: " + eventID +
" Length: " + length);
if (records != null)
{
Logger.IncrementProtocolIndent();
foreach (OpenTVRecordBase record in records)
record.LogMessage();
Logger.DecrementProtocolIndent();
}
}
private OpenTVRecordBase getRecord(int tag)
{
if (records == null)
return (null);
foreach (OpenTVRecordBase record in records)
{
if (record.Tag == tag)
return (record);
}
return (null);
}
}
}