From 42038a8cb9d3016abc96805e8f1dc292d98a71d4 Mon Sep 17 00:00:00 2001 From: saxon Date: Thu, 6 Dec 2018 01:28:14 +1030 Subject: [PATCH] psi: wrote Bytes() for TSS and almost done writing for PSI --- stream/mts/psi/psi.go | 47 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/stream/mts/psi/psi.go b/stream/mts/psi/psi.go index 3047106f..05cd2c3e 100644 --- a/stream/mts/psi/psi.go +++ b/stream/mts/psi/psi.go @@ -5,6 +5,8 @@ const ( DescDefLen = 2 PMTDefLen = 4 PATLen = 4 + TSSDefLen = 5 + PSIDefLen = 3 ) // Program specific information @@ -16,17 +18,17 @@ type PSI struct { pb bool // Private bit (0 for PAT, PMT, CAT) sl uint16 // Section length tss *TSS // Table syntax section (length defined by SL) if length 0 then nil + crc uint32 // crc32 of entire table excluding pointer field, pointer filler bytes and the trailing CRC32 } // Table syntax section type TSS struct { - tie uint16 // Table ID extension - v byte // Version number - cni bool // Current/next indicator - sn byte // Section number - lsn byte // Last section number - sd SD // Specific data PAT/PMT - crc []byte // crc32 of entire table excluding pointer field, pointer filler bytes and the trailing CRC32 + tide uint16 // Table ID extension + v byte // Version number + cni bool // Current/next indicator + sn byte // Section number + lsn byte // Last section number + sd SD // Specific data PAT/PMT } // Specific Data, (could be PAT or PMT) @@ -63,15 +65,35 @@ type Desc struct { dd []byte // Descriptor data } +// TODO: Implement this func ReadPSI(data []byte) *PSI { return nil } -func (p *PSI) Bytes() (out []byte) { +func (p *PSI) Bytes() []byte { + l := 1 + len(p.pfb) + out := make([]byte, l+PSIDefLen) + out[0] = p.pf + for i, b := range p.pfb { + out[1+i] = b + } + out[l] = p.tid + out[l+1] = 0x80 | 0x40 | 0x30 | (0x03 & byte(p.sl>>8)) + out[l+2] = byte(p.sl) + out = append(out, p.tss.Bytes()...) + crc32 := crc32_op() return nil } -func (t *TSS) Fill(s []byte) { +func (t *TSS) Bytes() []byte { + out := make([]byte, TSSDefLen) + out[0] = byte(t.tide >> 8) + out[1] = byte(t.tide) + out[2] = 0xc0 | (0x3e & (t.v << 1)) | (0x01 & boolToByte(t.cni)) + out[3] = t.sn + out[4] = t.lsn + out = append(out, t.sd.Bytes()...) + return out } func (p *PAT) Bytes() []byte { @@ -118,3 +140,10 @@ func (e *ESSD) Bytes() []byte { } return out } + +func boolToByte(b bool) byte { + if b { + return 0x01 + } + return 0x00 +}