public bool DecodeTeletextData(Pes pes) { if (pes.PacketStartCodePrefix != Pes.DefaultPacketStartCodePrefix || pes.StreamId != Pes.PrivateStream1 || pes.PesPacketLength <= 0) return false; ushort startOfSubtitleData = 7; if (pes.OptionalPesHeader.MarkerBits == 2) { startOfSubtitleData += (ushort)(3 + pes.OptionalPesHeader.PesHeaderLength); } while (startOfSubtitleData <= pes.PesPacketLength) { var dataUnitId = pes.Data[startOfSubtitleData]; var dataUnitLenght = pes.Data[startOfSubtitleData + 1]; if ((dataUnitId == DataUnitEbuTeletextNonsubtitle || dataUnitId == DataUnitEbuTeletextSubtitle) && dataUnitLenght == SizeOfTeletextPayload) { var data = new byte[dataUnitLenght + 2]; Buffer.BlockCopy(pes.Data, startOfSubtitleData, data, 0, dataUnitLenght + 2); //ETS 300 706 7.1 Utils.ReverseArray(ref data, 2, dataUnitLenght); DecodeTeletextDataInternal(data); } startOfSubtitleData += (ushort)(dataUnitLenght + 2); } return false; }
public void AddPacket(TsDecoder.TransportStream.TsDecoder tsDecoder, TsPacket tsPacket) { if (_currentTeletextDescriptor == null) { Setup(tsDecoder); if (_currentTeletextDescriptor != null) { Debug.WriteLine($"Locked onto teletext PID for {TeletextPid} "); } } if (tsPacket.Pid != TeletextPid) return; if (tsPacket.PayloadUnitStartIndicator) { if (_currentTeletextPes != null) { if (_currentTeletextPes.HasAllBytes()) { _currentTeletextPes.Decode(); foreach (var key in _teletextSubtitlePage.Keys) { _teletextSubtitlePage[key].DecodeTeletextData(_currentTeletextPes); } } } _currentTeletextPes = new Pes(tsPacket); } else { _currentTeletextPes?.Add(tsPacket); } }