mirror of https://bitbucket.org/ausocean/av.git
Merged in remove-read-funcs-in-psi-pkg (pull request #98)
mts/psi: remove read funcs as we're not using them at this time Approved-by: kortschak <dan@kortschak.io>
This commit is contained in:
commit
28d23ad200
|
@ -118,109 +118,6 @@ type Desc struct {
|
|||
Dd []byte // Descriptor data
|
||||
}
|
||||
|
||||
// ReadPSI creates a PSI data structure from a given byte slice that represents a PSI
|
||||
func ReadPSI(data []byte) *PSI {
|
||||
psi := PSI{}
|
||||
pos := 0
|
||||
psi.Pf = data[pos]
|
||||
if psi.Pf != 0 {
|
||||
panic("No support for pointer filler bytes")
|
||||
}
|
||||
psi.Tid = data[pos]
|
||||
pos++
|
||||
psi.Ssi = byteToBool(data[pos] & 0x80)
|
||||
psi.Pb = byteToBool(data[pos] & 0x40)
|
||||
psi.Sl = uint16(data[pos]&0x03)<<8 | uint16(data[pos+1])
|
||||
pos += 2
|
||||
psi.Tss = readTSS(data[pos:], &psi)
|
||||
return &psi
|
||||
}
|
||||
|
||||
// ReadTSS creates a TSS data structure from a given byte slice that represents a TSS
|
||||
func readTSS(data []byte, p *PSI) *TSS {
|
||||
tss := TSS{}
|
||||
pos := 0
|
||||
tss.Tide = uint16(data[pos])<<8 | uint16(data[pos+1])
|
||||
pos += 2
|
||||
tss.V = (data[pos] & 0x3e) >> 1
|
||||
tss.Cni = byteToBool(data[pos] & 0x01)
|
||||
pos++
|
||||
tss.Sn = data[pos]
|
||||
pos++
|
||||
tss.Lsn = data[pos]
|
||||
pos++
|
||||
switch p.Tid {
|
||||
case PATTableID:
|
||||
tss.Sd = readPAT(data[pos:], &tss)
|
||||
case PMTTableID:
|
||||
tss.Sd = readPMT(data[pos:], &tss)
|
||||
default:
|
||||
panic("Can't yet deal with tables that are not PAT or PMT")
|
||||
}
|
||||
return &tss
|
||||
}
|
||||
|
||||
// readPAT creates a pat struct based on a bytes slice representing a pat
|
||||
func readPAT(data []byte, p *TSS) *PAT {
|
||||
pat := PAT{}
|
||||
pos := 0
|
||||
pat.Pn = uint16(data[pos])<<8 | uint16(data[pos+1])
|
||||
pos += 2
|
||||
pat.Pmpid = uint16(data[pos]&0x1f)<<8 | uint16(data[pos+1])
|
||||
return &pat
|
||||
}
|
||||
|
||||
// readPMT creates a pmt struct based on a bytes slice that represents a pmt
|
||||
func readPMT(data []byte, p *TSS) *PAT {
|
||||
pmt := PMT{}
|
||||
pos := 0
|
||||
pmt.Pcrpid = uint16(data[pos]&0x1f)<<8 | uint16(data[pos+1])
|
||||
pos += 2
|
||||
pmt.Pil = uint16(data[pos]&0x03)<<8 | uint16(data[pos+1])
|
||||
pos += 2
|
||||
if pmt.Pil != 0 {
|
||||
pmt.Pd = readDescs(data[pos:], int(pmt.Pil))
|
||||
}
|
||||
pos += int(pmt.Pil)
|
||||
// TODO Read ES stuff
|
||||
pmt.Essd = readEssd(data[pos:])
|
||||
return nil
|
||||
}
|
||||
|
||||
// readDescs reads provides a slice of Descs given a byte slice that represents Descs
|
||||
// and the no of bytes that the descs accumilate
|
||||
func readDescs(data []byte, descLen int) (o []Desc) {
|
||||
pos := 0
|
||||
o = make([]Desc, 1)
|
||||
o[0].Dt = data[pos]
|
||||
pos++
|
||||
o[0].Dl = data[pos]
|
||||
pos++
|
||||
o[0].Dd = make([]byte, o[0].Dl)
|
||||
for i := 0; i < int(o[0].Dl); i++ {
|
||||
o[0].Dd[i] = data[pos]
|
||||
pos++
|
||||
}
|
||||
if 2+len(o[0].Dd) != descLen {
|
||||
panic("No support for reading more than one descriptor")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// readEESD creates an ESSD struct based on a bytes slice that represents ESSD
|
||||
func readEssd(data []byte) *ESSD {
|
||||
essd := ESSD{}
|
||||
pos := 0
|
||||
essd.St = data[pos]
|
||||
pos++
|
||||
essd.Epid = uint16(data[pos]&0x1f)<<8 | uint16(data[pos+1])
|
||||
pos += 2
|
||||
essd.Esil = uint16(data[pos]&0x03)<<8 | uint16(data[pos+1])
|
||||
pos += 2
|
||||
essd.Esd = readDescs(data[pos:], int(essd.Esil))
|
||||
return &essd
|
||||
}
|
||||
|
||||
// Bytes outputs a byte slice representation of the PSI
|
||||
func (p *PSI) Bytes() []byte {
|
||||
out := make([]byte, 4)
|
||||
|
|
Loading…
Reference in New Issue