diff --git a/stream/mts/psi/psi.go b/stream/mts/psi/psi.go index ee874b6c..6a88fc50 100644 --- a/stream/mts/psi/psi.go +++ b/stream/mts/psi/psi.go @@ -20,7 +20,7 @@ var ( // syntax section 0x00, 0x01, // table id extension - 0xc1, // reserved bits:3|version:5|use now:1 1100 0001 + 0xc1, // reserved bits:2|version:5|use now:1 1100 0001 0x00, // section number 0x00, // last section number // table data @@ -141,12 +141,7 @@ func ReadPSI(data []byte) *PSI { pos := 0 psi.Pf = data[pos] if psi.Pf != 0 { - psi.Pfb = make([]byte, 0, psi.Pf) - pos++ - for i := 0; i < int(psi.Pf); i++ { - psi.Pfb = append(psi.Pfb, data[pos]) - pos++ - } + panic("No support for pointer filler bytes") } psi.Tid = data[pos] pos++ @@ -242,17 +237,16 @@ func readEssd(data []byte) *ESSD { // Bytes outputs a byte slice representation of the PSI func (p *PSI) Bytes() []byte { - l := 1 + len(p.Pfb) - out := make([]byte, l+PSIDefLen) + out := make([]byte, 4) out[0] = p.Pf - for i, b := range p.Pfb { - out[1+i] = b + if p.Pf != 0 { + panic("No support for pointer filler bytes") } - out[l] = p.Tid - out[l+1] = 0x80 | 0x40 | 0x30 | (0x03 & byte(p.Sl>>8)) - out[l+2] = byte(p.Sl) + out[1] = p.Tid + out[2] = 0x80 | 0x30 | (0x03 & byte(p.Sl>>8)) + out[3] = byte(p.Sl) out = append(out, p.Tss.Bytes()...) - crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), out[l:]) + crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), out[3:]) out = append(out, make([]byte, 0, 4)...) out = append(out, byte(crc32>>24)) out = append(out, byte(crc32>>16)) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index 0ca5e2e9..4d09dd6c 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -1,6 +1,7 @@ package psi import ( + "bytes" "testing" ) @@ -19,34 +20,48 @@ var ( Lsn: 0, Sd: &PAT{ Pn: uint16(0x01), - Pmpid: 16, + Pmpid: uint16(0x1000), }, }, } pmtPsi = PSI{ - Pf: 0x00, + Pf: 0x00, Tid: 0x02, Ssi: true, - Sl: uint16(0x12), - Tss: & TSS{ + Sl: uint16(0x12), + Tss: &TSS{ Tide: uint16(0x01), - V:0, - Cni: true, - Sn: 0, - Lsn: 0, + V: 0, + Cni: true, + Sn: 0, + Lsn: 0, Sd: &PMT{ - Pcrpid: 16, // wrong - Pil: 0, + Pcrpid: 0x1100, // wrong + Pil: 0, Essd: &ESSD{ - St: 0x1b, - - } - } - } - } + St: 0x1b, + Epid: 0x0100, + Esil: 0x00, + }, + }, + }, } ) -func TestReadPSI1(t *testing.T) { - +func TestWritePAT1(t *testing.T) { + got := patPsi.Bytes() + // Remove crc32 + got = got[:len(got)-4] + if !bytes.Equal(StdPat, got[:len(got)-4]) { + t.Errorf("Incorrect output, wanted: %v, got: %v", StdPat, got) + } +} + +func TestWritePMT1(t *testing.T) { + got := pmtPsi.Bytes() + // Remove crc32 + got = got[:len(got)-4] + if !bytes.Equal(StdPmt, got[:len(got)-4]) { + t.Errorf("Incorrect output, wanted: %v, got: %v", StdPmt, got) + } }