From 5f0bef93650d023913d3403e554a881228aa7312 Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 4 Dec 2018 16:03:04 +1030 Subject: [PATCH] psi: writing new data strcutres to make things neater and more usable --- stream/mts/psi/pmt.go | 16 +++++++++++++++- stream/mts/psi/psi.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 stream/mts/psi/psi.go diff --git a/stream/mts/psi/pmt.go b/stream/mts/psi/pmt.go index 2971e8c0..9def4e60 100644 --- a/stream/mts/psi/pmt.go +++ b/stream/mts/psi/pmt.go @@ -27,6 +27,18 @@ LICENSE package psi +// Bitmasks +const ( + // bitmasks used for second byte + SYNTAX_INDICATOR = 0x80 + PRIVATE_BIT = 0x40 + RESERVED_BITS = 0x30 + SECTION_LENGTH_1 = 0x03 // first two bits of the section length + + // bitmasks used for third byte + SECTION_LENGTH_2 = 0xff +) + type PMT struct { PF byte // Point field PFB []byte // pointer filler bytes @@ -39,9 +51,11 @@ type PMT struct { CNI bool // Current/next indicator Section byte // Section number LSN byte // Last section number - } +func ReadPMT(pmtData []byte) (PMT, error) { + return PMT{}, nil +} func (p *PMT) ToByteSlice() (output []byte) { return } diff --git a/stream/mts/psi/psi.go b/stream/mts/psi/psi.go new file mode 100644 index 00000000..13816f15 --- /dev/null +++ b/stream/mts/psi/psi.go @@ -0,0 +1,36 @@ +package psi + +// Program specific information +type PSI struct { + PF byte // Point field + PFB []byte // pointer filler bytes + TableID byte // Table ID + SSI bool // Sectiopn syntax indicator (1 for PAT, PMT, CAT) + 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 +} + +// Table syntax section +type TSS struct { + TIE uint16 // Table ID extension + Version byte // Version number + CNI bool // Current/next indicator + Section byte // Section number + LSN byte // Last section number + table SD // specific data PAT/PMT +} + +// Specific Data, which could be PAT or PMT +type SD interface { + Read(psiData []byte) (PSI, error) + ToByte() []byte +} + +func (p *PSI) Read(psiData []byte) (PSI, error) { + return PSI{}, nil +} + +func (p *PSI) ToByte() []byte { + return nil +}