public override void ToBuffer(ref TSMessagePackWriter writer) { writer.WriteByte(Tag); writer.Skip(1, out var position); writer.WriteByte((byte)ServiceType); writer.Skip(1, out var serviceProviderLengthPosition); writer.WriteString(ServiceProvider); writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - serviceProviderLengthPosition - 1), serviceProviderLengthPosition); writer.Skip(1, out int SeviceNameLengthPosition); writer.WriteString(ServiceName); writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - SeviceNameLengthPosition - 1), SeviceNameLengthPosition); writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - position - 1), position); }
public void ToBuffer(ref TSMessagePackWriter writer) { Header.ToBuffer(ref writer); writer.WriteByte(TableId); //SectionSyntaxIndicator Zero Reserved1 SectionLength //1 0 11 0000 0000 0000 //(ushort)(0b_1011_0000_0000_0000 | SectionLength) writer.Skip(2, out int SectionLengthPosition); writer.WriteUInt16(TransportStreamId); //Reserved2 VersionNumber CurrentNextIndicator //11 00000 1 var a = 0xC0 & (Reserved2 << 6); var b = 0x3E & (VersionNumber << 3); var c = (byte)(a | b | CurrentNextIndicator); writer.WriteByte(c); writer.WriteByte(SectionNumber); writer.WriteByte(LastSectionNumber); if (Programs != null) { foreach (var program in Programs) { program.ToBuffer(ref writer); } } const int crcLength = 4; writer.WriteUInt16Return((ushort)(0b_1011_0000_0000_0000 | (ushort)(writer.GetCurrentPosition() - SectionLengthPosition - 2) + crcLength), SectionLengthPosition); //打包ts流时PAT和PMT表是没有adaptation field的,不够的长度直接补0xff即可。 //ts header(4B) + adaptation field length(1) writer.WriteCRC32(5); var size = TSConstants.FiexdPackageLength - writer.GetCurrentPosition(); writer.WriteArray(Enumerable.Range(0, size).Select(s => (byte)0xFF).ToArray()); }
public void ToBuffer(ref TSMessagePackWriter writer) { writer.WriteByte(SyncByte); //TransportErrorIndicator PayloadUnitStartIndicator TransportPriority PID //0 1 0 0000 0000 0000 0 //writer.WriteUInt16((ushort)((0b_0100_0000_0000_0000 & (PayloadUnitStartIndicator<<14)) | PID)); writer.WriteUInt16((ushort)((TransportErrorIndicator << 15) | (PayloadUnitStartIndicator << 14) | PID)); writer.WriteByte((byte)((byte)AdaptationFieldControl | ContinuityCounter)); if (PackageType == PackageType.PAT || PackageType == PackageType.PMT || PackageType == PackageType.Data_Start || PackageType == PackageType.Data_End || PackageType == PackageType.SDT) { if (Adaptation != null) { writer.Skip(1, out int AdaptationLengthPosition); Adaptation.ToBuffer(ref writer); writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - AdaptationLengthPosition - 1), AdaptationLengthPosition); } else { writer.WriteByte(0); } } }
public void ToBuffer(ref TSMessagePackWriter writer) { Header.PackageType = PackageType.SDT; Header.ToBuffer(ref writer); writer.WriteByte(TableId); writer.Skip(2, out int SectionLengthPosition); writer.WriteUInt16(TransportStreamId); writer.WriteByte((byte)(Reserved2 << 6 | VersionNumber << 1 | CurrentNextIndicator)); writer.WriteByte(SectionNumber); writer.WriteByte(LastSectionNumber); writer.WriteUInt16(OriginalNetworkId); writer.WriteByte(ReservedFutureUse2); foreach (var service in Services) { service.ToBuffer(ref writer); } ushort servicesLength = (ushort)(writer.GetCurrentPosition() - SectionLengthPosition - 2); const int crcLength = 4; writer.WriteUInt16Return((ushort)(SectionSyntaxIndicator << 15 | ReservedFutureUse1 << 14 | Reserved1 << 12 | servicesLength + crcLength), SectionLengthPosition); writer.WriteCRC32(5); var size = TSConstants.FiexdPackageLength - writer.GetCurrentPosition(); writer.WriteArray(Enumerable.Range(0, size).Select(s => (byte)0xFF).ToArray()); }
public void ToBuffer(ref TSMessagePackWriter writer) { writer.WriteUInt16(ServiceId); writer.WriteByte((byte)(ReservedFutureUse << 2 | EITScheduleFlag << 1 | EITPresentFollowingFlag)); writer.Skip(2, out var position); foreach (var descriptor in Descriptors) { descriptor.ToBuffer(ref writer); } DescriptorsLoopLength = (ushort)(writer.GetCurrentPosition() - position - 2); writer.WriteUInt16Return((ushort)((ushort)RunningStatus << 13 | (ushort)FreeCAMode << 12 | DescriptorsLoopLength), position); }
public void ToBuffer(ref TSMessagePackWriter writer) { writer.WriteByte((byte)StreamType); writer.WriteUInt16((ushort)(0b_1110_0000_0000_0000 | ElementaryPID)); if (Descriptor == null) { writer.WriteUInt16((ushort)(0b_1111_0000_0000_0000 | ESInfoLength)); } else { writer.Skip(2, out int ESInfoLengthPosition); Descriptor.ToBuffer(ref writer); ESInfoLength = (ushort)(writer.GetCurrentPosition() - ESInfoLengthPosition - 2); writer.WriteUInt16Return((ushort)(0b_1111_0000_0000_0000 | ESInfoLength), ESInfoLengthPosition); } }
public void ToBuffer(ref TSMessagePackWriter writer) { writer.WriteByte(SyncByte); //TransportErrorIndicator PayloadUnitStartIndicator TransportPriority PID //0 1 0 0000 0000 0000 0 writer.WriteUInt16((ushort)(0b_0100_0000_0000_0000 | PID)); writer.WriteByte((byte)((byte)AdaptationFieldControl | ContinuityCounter)); if (Adaptation != null) { writer.Skip(1, out int AdaptationLengthPosition); Adaptation.ToBuffer(ref writer); writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - AdaptationLengthPosition - 1), AdaptationLengthPosition); } else { writer.WriteByte(0); } }
public override void ToBuffer(ref TSMessagePackWriter writer) { writer.WriteByte(Tag); if (ISO_639_Language_Infos != null) { writer.Skip(1, out int DescriptorLengthPosition); foreach (var item in ISO_639_Language_Infos) { writer.WriteUInt3(item.ISO_639_Language_Code >> 8); writer.WriteByte(item.Audio_Type); } writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - DescriptorLengthPosition - 1), DescriptorLengthPosition); } else { writer.WriteByte(0); } }