public void Decode(byte[] section) { if (OnTableComplete == null) { return; } if (section.Length < 14) { Log.Log.Error("NTT: invalid section size {0}, expected at least 14 bytes", section.Length); return; } byte tableId = section[2]; if (tableId != 0xc3) { return; } int sectionLength = ((section[3] & 0x0f) << 8) + section[4]; if (section.Length != 2 + sectionLength + 3) // 2 for section length bytes, 3 for table ID and PID { Log.Log.Error("NTT: invalid section length = {0}, byte count = {1}", sectionLength, section.Length); return; } int protocolVersion = (section[5] & 0x1f); string isoLangCode = System.Text.Encoding.ASCII.GetString(section, 6, 3); AtscTransmissionMedium transmissionMedium = (AtscTransmissionMedium)(section[9] >> 4); TableSubtype tableSubtype = (TableSubtype)(section[9] & 0x0f); Log.Log.Debug("NTT: section length = {0}, protocol version = {1}, ISO language code = {2}, transmission medium = {3}, table subtype = {4}", sectionLength, protocolVersion, isoLangCode, transmissionMedium, tableSubtype); int pointer = 10; int endOfSection = section.Length - 4; try { switch (tableSubtype) { case TableSubtype.TransponderName: DecodeTransponderName(section, endOfSection, ref pointer); break; case TableSubtype.SatelliteText: DecodeSatelliteText(section, endOfSection, ref pointer); break; case TableSubtype.RatingsText: DecodeRatingsText(section, endOfSection, ref pointer); break; case TableSubtype.RatingSystem: DecodeRatingSystem(section, endOfSection, ref pointer); break; case TableSubtype.CurrencySystem: DecodeCurrencySystem(section, endOfSection, ref pointer); break; case TableSubtype.SourceName: DecodeSourceName(section, endOfSection, ref pointer, transmissionMedium); break; case TableSubtype.MapName: DecodeMapName(section, endOfSection, ref pointer); break; default: Log.Log.Error("NTT: unsupported table subtype {0}", tableSubtype); return; } } catch (Exception ex) { Log.Log.Error(ex.Message); return; } while (pointer + 1 < endOfSection) { byte tag = section[pointer++]; byte length = section[pointer++]; Log.Log.Debug("NTT: descriptor, tag = 0x{0:x}, length = {1}", tag, length); if (pointer + length > endOfSection) { Log.Log.Error("NTT: invalid descriptor length {0}, pointer = {1}, end of section = {2}", length, pointer, endOfSection); return; } if (tag == 0x93) // revision detection descriptor { DecodeRevisionDetectionDescriptor(section, pointer, length, (int)tableSubtype); } pointer += length; } if (pointer != endOfSection) { Log.Log.Error("NTT: corruption detected at end of section, pointer = {0}, end of section = {1}", pointer, endOfSection); return; } if (tableSubtype == TableSubtype.SourceName && _currentVersions[(int)TableSubtype.SourceName] != -1 && _unseenSections[(int)TableSubtype.SourceName].Count == 0 && OnTableComplete != null) { OnTableComplete(MgtTableType.NttSns); OnTableComplete = null; OnSourceName = null; } }
public void Decode(byte[] section) { if (OnTableComplete == null) { return; } if (section.Length < 13) { Log.Log.Error("NIT: invalid section size {0}, expected at least 13 bytes", section.Length); return; } byte tableId = section[2]; if (tableId != 0xc2) { return; } int sectionLength = ((section[3] & 0xf) << 8) + section[4]; if (section.Length != 2 + sectionLength + 3) // 2 for section length bytes, 3 for table ID and PID { Log.Log.Error("NIT: invalid section length = {0}, byte count = {1}", sectionLength, section.Length); return; } int protocolVersion = (section[5] & 0x1f); byte firstIndex = section[6]; byte numberOfRecords = section[7]; AtscTransmissionMedium transmissionMedium = (AtscTransmissionMedium)(section[8] >> 4); TableSubtype tableSubtype = (TableSubtype)(section[8] & 0x0f); if ((tableSubtype != TableSubtype.CarrierDefinition || OnCarrierDefinition == null) && (tableSubtype != TableSubtype.ModulationMode || OnModulationMode == null)) { return; } int pointer = 9; int endOfSection = section.Length - 4; byte satelliteId = 0; if (tableSubtype == TableSubtype.TransponderData) { if (pointer >= endOfSection) { Log.Log.Error("NIT: invalid section length at satellite ID, pointer = {0}, end of section = {1}", pointer, endOfSection); return; } satelliteId = section[pointer++]; } Log.Log.Debug("NIT: section length = {0}, protocol version = {1}, first index = {2}, number of records = {3}, transmission medium = {4}, table subtype = {5}, satellite ID = {6}", sectionLength, protocolVersion, firstIndex, numberOfRecords, transmissionMedium, tableSubtype, satelliteId); for (byte i = 0; i < numberOfRecords; i++) { try { switch (tableSubtype) { case TableSubtype.CarrierDefinition: DecodeCarrierDefinition(section, endOfSection, ref pointer, ref firstIndex, transmissionMedium); break; case TableSubtype.ModulationMode: DecodeModulationMode(section, endOfSection, ref pointer, ref firstIndex, transmissionMedium); break; case TableSubtype.SatelliteInformation: DecodeSatelliteInformation(section, endOfSection, ref pointer); break; case TableSubtype.TransponderData: DecodeTransponderData(section, endOfSection, ref pointer); break; default: Log.Log.Error("NIT: unsupported table subtype {0}", tableSubtype); return; } } catch (Exception ex) { Log.Log.Error(ex.Message); return; } // table descriptors if (pointer >= endOfSection) { Log.Log.Error("NIT: invalid section length at table descriptor count, pointer = {0}, end of section = {1}, loop = {2}", pointer, endOfSection, i); return; } byte descriptorCount = section[pointer++]; for (byte d = 0; d < descriptorCount; d++) { if (pointer + 2 > endOfSection) { Log.Log.Error("NIT: detected table descriptor count {0} is invalid, pointer = {1}, end of section = {2}, loop = {3}, inner loop = {4}", descriptorCount, pointer, endOfSection, i, d); return; } byte tag = section[pointer++]; byte length = section[pointer++]; Log.Log.Debug("NIT: table descriptor, tag = 0x{0:x}, length = {1}", tag, length); if (pointer + length > endOfSection) { Log.Log.Error("NIT: invalid table descriptor length {0}, pointer = {1}, end of section = {2}, loop = {3}, inner loop = {4}", length, pointer, endOfSection, i, d); return; } pointer += length; } } while (pointer + 1 < endOfSection) { byte tag = section[pointer++]; byte length = section[pointer++]; Log.Log.Debug("NIT: descriptor, tag = 0x{0:x}, length = {1}", tag, length); if (pointer + length > endOfSection) { Log.Log.Error("NIT: invalid descriptor length {0}, pointer = {1}, end of section = {2}", length, pointer, endOfSection); return; } if (tag == 0x93) { DecodeRevisionDetectionDescriptor(section, pointer, length, (int)tableSubtype); } pointer += length; } if (pointer != endOfSection) { Log.Log.Error("NIT: corruption detected at end of section, pointer = {0}, end of section = {1}", pointer, endOfSection); return; } if (tableSubtype == TableSubtype.CarrierDefinition && ( _currentVersions[(int)TableSubtype.CarrierDefinition] == -1 || _unseenSections[(int)TableSubtype.CarrierDefinition].Count == 0 ) && OnCarrierDefinition != null) { OnCarrierDefinition = null; if (OnModulationMode == null && OnTableComplete != null) { OnTableComplete(MgtTableType.NitCds); OnTableComplete = null; } } else if (tableSubtype == TableSubtype.ModulationMode && ( _currentVersions[(int)TableSubtype.ModulationMode] == -1 || _unseenSections[(int)TableSubtype.ModulationMode].Count == 0 ) && OnModulationMode != null) { OnModulationMode = null; if (OnCarrierDefinition == null && OnTableComplete != null) { OnTableComplete(MgtTableType.NitMms); OnTableComplete = null; } } }
public void Decode(byte[] section) { if (OnTableComplete == null) { return; } if (section.Length < 13) { Log.Log.Error("S-VCT: invalid section size {0}, expected at least 13 bytes", section.Length); return; } byte tableId = section[2]; if (tableId != 0xc4) { return; } int sectionLength = ((section[3] & 0x0f) << 8) + section[4]; if (section.Length != 2 + sectionLength + 3) // 2 for section length bytes, 3 for table ID and PID { Log.Log.Error("S-VCT: invalid section length = {0}, byte count = {1}", sectionLength, section.Length); return; } byte protocolVersion = (byte)(section[5] & 0x1f); AtscTransmissionMedium transmissionMedium = (AtscTransmissionMedium)(section[6] >> 4); TableSubtype tableSubtype = (TableSubtype)(section[6] & 0x0f); int vctId = (section[7] << 8) + section[8]; Log.Log.Debug("S-VCT: section length = {0}, protocol version = {1}, transmission medium = {2}, table subtype = {3}, VCT ID = 0x{4:x}", sectionLength, protocolVersion, transmissionMedium, tableSubtype, vctId); int pointer = 9; int endOfSection = section.Length - 4; try { switch (tableSubtype) { case TableSubtype.DefinedChannelMap: DecodeDefinedChannelMap(section, endOfSection, ref pointer); break; case TableSubtype.VirtualChannelMap: DecodeVirtualChannelMap(section, endOfSection, ref pointer, transmissionMedium, vctId); break; case TableSubtype.InverseChannelMap: DecodeInverseChannelMap(section, endOfSection, ref pointer); break; default: Log.Log.Error("S-VCT: unsupported table subtype {0}", tableSubtype); return; } } catch (Exception ex) { Log.Log.Error(ex.Message); return; } while (pointer + 1 < endOfSection) { byte tag = section[pointer++]; byte length = section[pointer++]; Log.Log.Debug("S-VCT: descriptor, tag = 0x{0:x}, length = {1}", tag, length); if (pointer + length > endOfSection) { Log.Log.Error("S-VCT: invalid descriptor length {0}, pointer = {1}, end of section = {2}", length, pointer, endOfSection); return; } if (tag == 0x93) // revision detection descriptor { DecodeRevisionDetectionDescriptor(section, pointer, length, (int)tableSubtype); } pointer += length; } if (pointer != endOfSection) { Log.Log.Error("S-VCT: corruption detected at end of section, pointer = {0}, end of section = {1}", pointer, endOfSection); return; } // Two methods for detecting S-VCT VCM completion: // 1. Revision detection descriptors. // 2. DCM channel count equals VCM channel count. if ( ( tableSubtype == TableSubtype.VirtualChannelMap && _currentVersions[(int)TableSubtype.VirtualChannelMap] != -1 && _unseenSections[(int)TableSubtype.VirtualChannelMap].Count == 0 && OnTableComplete != null ) || ( (tableSubtype == TableSubtype.DefinedChannelMap || tableSubtype == TableSubtype.VirtualChannelMap) && _currentVersions[(int)TableSubtype.VirtualChannelMap] == -1 && _channelDefinitions.Count == _definedChannels.Count && OnTableComplete != null ) ) { OnTableComplete(MgtTableType.SvctVcm); OnTableComplete = null; OnChannelDetail = null; } }