private bool createMpeg2Section(Collection<Mpeg2Section> sections) { if (RunParameters.Instance.TraceIDs.Contains("PIDHANDLER")) Logger.Instance.Write(getPidID() + "Creating MPEG2 section"); mpeg2Section = new Mpeg2Section(); mpeg2Section.Data = new byte[length + 3]; mpeg2Section.Length = length + 3; mpeg2Section.PID = pid; mpeg2Section.Data[0] = table; mpeg2Section.Data[1] = lengthByte1; mpeg2Section.Data[2] = lengthByte2; for (sectionIndex = 3; sectionIndex < length + 3; sectionIndex++) { if (packetIndex == siPacket.ByteData.Length) { if (RunParameters.Instance.TraceIDs.Contains("PIDHANDLER")) Logger.Instance.Write(getPidID() + "Need more data"); status = handlerStatus.awaitingMoreData; return (false); } mpeg2Section.Data[sectionIndex] = siPacket.ByteData[packetIndex]; packetIndex++; } if (RunParameters.Instance.TraceIDs.Contains("PIDHANDLER")) Logger.Instance.Write(getPidID() + "Got table"); if ((mpeg2Section.Data[1] & 0x80) != 0) { bool checkCRC = mpeg2Section.CheckCRC(); if (!checkCRC) { Logger.Instance.Write(getPidID() + "CRC failed"); return (true); } } sections.Add(mpeg2Section); if (RunParameters.Instance.TraceIDs.Contains("PIDHANDLER")) Logger.Instance.Dump(getPidID() + "MPEG2 Section", mpeg2Section.Data, mpeg2Section.Data.Length); return (true); }
private void processDataSection(Mpeg2Section section) { Mpeg2ExtendedHeader mpeg2Header = new Mpeg2ExtendedHeader(); try { mpeg2Header.Process(section.Data); if (mpeg2Header.Current) { DSMCCSection dsmccSection = new DSMCCSection(); dsmccSection.Process(section.Data, mpeg2Header); if (dsmccSection.DSMCCMessage as DSMCCDownloadDataBlock != null) addDDBMessage(dsmccSection.DSMCCMessage as DSMCCDownloadDataBlock); } } catch (ArgumentOutOfRangeException e) { Logger.Instance.Write("<e> Error processing DSMCC data message: " + e.Message); } }
private void getSection(BackgroundParameters parameters) { if (siPacket == null) { siPacket = getPacket(true); if (siPacket == null) { Thread.Sleep(500); return; } packetIndex = siPacket.DataIndex; } if (packetIndex > siPacket.ByteData.Length - 1) { siPacket = null; return; } byte table = siPacket.ByteData[packetIndex]; if (table == 0xff) { siPacket = null; return; } if (packetIndex == siPacket.ByteData.Length - 1) { siPacket = getPacket(false); if (siPacket == null) { Thread.Sleep(500); return; } packetIndex = siPacket.Index; } else packetIndex++; byte lengthByte1 = siPacket.ByteData[packetIndex]; if (packetIndex == siPacket.ByteData.Length - 1) { siPacket = getPacket(false); if (siPacket == null) { Thread.Sleep(500); return; } packetIndex = siPacket.Index; } else packetIndex++; byte lengthByte2 = siPacket.ByteData[packetIndex]; packetIndex++; int length = ((lengthByte1 & 0x0f) * 256) + lengthByte2; if (length < 2) { packetIndex += length; return; } if (tables != null && !tables.Contains(table)) { packetIndex += length; return; } mpeg2Section = new Mpeg2Section(); mpeg2Section.Data = new byte[length + 3]; mpeg2Section.Length = length + 3; mpeg2Section.Data[0] = table; mpeg2Section.Data[1] = lengthByte1; mpeg2Section.Data[2] = lengthByte2; for (int index = 3; index < length + 3; index++) { if (packetIndex == siPacket.ByteData.Length) { siPacket = getPacket(false); if (siPacket == null) { Thread.Sleep(500); return; } packetIndex = siPacket.Index; } mpeg2Section.Data[index] = siPacket.ByteData[packetIndex]; packetIndex++; } if ((mpeg2Section.Data[1] & 0x80) == 1) { bool checkCRC = mpeg2Section.CheckCRC(); if (!checkCRC) return; } Lock("GetSection"); if (Sections.Count < parameters.MaxSections) Sections.Add(mpeg2Section); Release("GetSection"); }
private void processControlSection(Mpeg2Section section) { Mpeg2ExtendedHeader mpeg2Header = new Mpeg2ExtendedHeader(); try { mpeg2Header.Process(section.Data); if (mpeg2Header.Current) { DSMCCSection dsmccSection = new DSMCCSection(); dsmccSection.Process(section.Data, mpeg2Header); if (dsmccSection.DSMCCMessage as DSMCCDownloadServerInitiate != null) addDSIMessage(dsmccSection.DSMCCMessage as DSMCCDownloadServerInitiate); else { if (dsmccSection.DSMCCMessage as DSMCCDownloadInfoIndication != null) addDIIMessage(dsmccSection.DSMCCMessage as DSMCCDownloadInfoIndication); else { if (dsmccSection.DSMCCMessage as DSMCCDownloadCancel != null) { Logger.Instance.Write("DSMCC Cancel message received: reloading all data"); dsiMessage = null; diiMessages = null; modules = null; } } } } } catch (ArgumentOutOfRangeException e) { Logger.Instance.Write("<e> Error processing DSMCC control message: " + e.Message); } }