////////////////////////////////////////////////////////////////////////////////// // // // 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 a MediaHighway channel info entry. /// public class MediaHighwayChannelInfoEntry { /// /// Get the original network ID for the channel. /// public int OriginalNetworkID { get { return (originalNetworkID); } } /// /// Get the transport stream ID for the channel. /// public int TransportStreamID { get { return (transportStreamID); } } /// /// Get the service ID for the channel. /// public int ServiceID { get { return (serviceID); } } /// /// Get the name of the channel. /// public string Name { get { return (name); } } /// /// Get the unknown data. /// public byte[] Unknown { get { return (unknown); } } /// /// Get the index of the next byte in the section following this entry. /// /// /// The entry has not been processed. /// public int Index { get { if (lastIndex == -1) throw (new InvalidOperationException("MediaHighwayChannelEntry: Index requested before block processed")); return (lastIndex); } } /// /// Get the index of the next name byte in the section following this entry. /// /// /// The entry has not been processed. /// public int NameIndex { get { if (nameIndex == -1) throw (new InvalidOperationException("MediaHighwayChannelEntry: Name index requested before block processed")); return (nameIndex); } } /// /// Get the length of the entry. /// public int Length { get { return (length); } } private int originalNetworkID; private int transportStreamID; private int serviceID; private string name; private byte[] unknown; private int lastIndex = -1; private int nameIndex; private int length; /// /// Initialize a new instance of the MediaHighwayChannelInfoEntry. /// public MediaHighwayChannelInfoEntry() { } /// /// Parse the MHW1 descriptor. /// /// The MPEG2 section containing the entry. /// Index of the first byte in the MPEG2 section of the entry. internal void Process(byte[] byteData, int index) { lastIndex = index; try { originalNetworkID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; transportStreamID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; serviceID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; name = Utils.GetString(byteData, lastIndex, 16, ReplaceMode.TransferUnchanged).Trim(); lastIndex += 16; length = lastIndex - index; Validate(); } catch (IndexOutOfRangeException) { throw (new ArgumentOutOfRangeException("The MediaHighway Channel Info Entry message is short")); } } /// /// Parse the MHW2 descriptor. /// /// The MPEG2 section containing the entry. /// Index of the first byte in the MPEG2 section of the entry. /// Index of the first byte channel name in the MPEG2 section of the entry. internal void Process(byte[] byteData, int index, int nameLengthIndex) { lastIndex = index; nameIndex = nameLengthIndex; try { originalNetworkID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; transportStreamID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; serviceID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; unknown = Utils.GetBytes(byteData, lastIndex, 2); lastIndex += unknown.Length; int nameLength = (int)byteData[nameIndex] & 0x3f; nameIndex++; name = Utils.GetString(byteData, nameIndex, nameLength, ReplaceMode.TransferUnchanged).Trim(); nameIndex += nameLength; length = lastIndex - index; Validate(); } catch (IndexOutOfRangeException) { throw (new ArgumentOutOfRangeException("The MediaHighway Channel Info Entry message is short")); } catch (NotImplementedException e) { throw e; } } /// /// Validate the entry fields. /// /// /// A descriptor field is not valid. /// internal void Validate() { } /// /// Log the entry fields. /// internal void LogMessage() { if (Logger.ProtocolLogger == null) return; string unknownString; if (unknown == null) unknownString = "n/a"; else unknownString = Utils.ConvertToHex(unknown); Logger.ProtocolLogger.Write(Logger.ProtocolIndent + "MHW CHANNEL INFO ENTRY: ONID: " + originalNetworkID + " TSID: " + transportStreamID + " SID: " + serviceID + " Name: " + name + " Unknown: " + unknownString); } } }