2018-12-04 08:33:04 +03:00
|
|
|
package psi
|
|
|
|
|
2018-12-05 14:16:06 +03:00
|
|
|
const (
|
2018-12-05 14:17:16 +03:00
|
|
|
ESSDHeadLen = 5
|
|
|
|
DescHeadLen = 2
|
2018-12-05 14:16:06 +03:00
|
|
|
)
|
|
|
|
|
2018-12-04 08:33:04 +03:00
|
|
|
// Program specific information
|
|
|
|
type PSI struct {
|
2018-12-05 12:01:29 +03:00
|
|
|
pf byte // Point field
|
2018-12-05 14:16:06 +03:00
|
|
|
pfb []byte // Pointer filler bytes
|
2018-12-05 12:01:29 +03:00
|
|
|
tid byte // Table ID
|
2018-12-05 16:34:19 +03:00
|
|
|
ssi bool // Section syntax indicator (1 for PAT, PMT, CAT)
|
2018-12-05 12:01:29 +03:00
|
|
|
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
|
2018-12-04 08:33:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Table syntax section
|
|
|
|
type TSS struct {
|
2018-12-05 12:01:29 +03:00
|
|
|
tie uint16 // Table ID extension
|
|
|
|
v byte // Version number
|
|
|
|
cni bool // Current/next indicator
|
|
|
|
sn byte // Section number
|
|
|
|
lsn byte // Last section number
|
2018-12-05 14:16:06 +03:00
|
|
|
sd SD // Specific data PAT/PMT
|
2018-12-05 12:01:29 +03:00
|
|
|
crc []byte // crc32 of entire table excluding pointer field, pointer filler bytes and the trailing CRC32
|
2018-12-04 08:33:04 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:01:29 +03:00
|
|
|
// Specific Data, (could be PAT or PMT)
|
2018-12-04 08:33:04 +03:00
|
|
|
type SD interface {
|
2018-12-05 12:01:29 +03:00
|
|
|
Bytes() []byte
|
2018-12-04 08:33:04 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:01:29 +03:00
|
|
|
// Program association table, implements SD
|
|
|
|
type PAT struct {
|
|
|
|
pn uint16 // Program Number
|
2018-12-05 14:16:06 +03:00
|
|
|
pmpid uint16 // Program map PID
|
|
|
|
}
|
|
|
|
|
|
|
|
// Program mapping table, implements SD
|
|
|
|
type PMT struct {
|
2018-12-05 14:17:16 +03:00
|
|
|
pcrpid uint16 // Program clock reference pid
|
|
|
|
pil uint16 // Program info length
|
|
|
|
pd []Desc // Program descriptors
|
|
|
|
essd []ESSD // Elementary stream specific data
|
2018-12-04 08:33:04 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 14:16:06 +03:00
|
|
|
// Elementary stream specific data
|
|
|
|
type ESSD struct {
|
2018-12-05 14:17:16 +03:00
|
|
|
st byte // Stream type
|
|
|
|
epid byte // Elementary pid
|
|
|
|
esil uint16 // Elementary stream
|
|
|
|
esd []Desc // Elementary stream desriptors
|
2018-12-05 14:16:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Descriptor
|
|
|
|
type Desc struct {
|
2018-12-05 12:01:29 +03:00
|
|
|
dt byte // Descriptor tag
|
|
|
|
dl byte // Descriptor length
|
|
|
|
dd []byte // Descriptor data
|
|
|
|
}
|
|
|
|
|
2018-12-05 14:16:06 +03:00
|
|
|
func ReadPSI(data []byte) *PSI {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PSI) Bytes() (out []byte) {
|
|
|
|
return nil
|
2018-12-05 12:01:29 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 16:34:19 +03:00
|
|
|
func (t *TSS) Fill(s []byte) {
|
2018-12-05 12:01:29 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 16:34:19 +03:00
|
|
|
func (p *PAT) Fill(s []byte) {
|
2018-12-05 12:01:29 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 16:34:19 +03:00
|
|
|
func (p *PMT) Bytes() (out []byte) {
|
2018-12-05 12:01:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-05 16:34:19 +03:00
|
|
|
func (d *Desc) Bytes() (out []byte) {
|
|
|
|
out = make([]byte, DescHeadLen)
|
|
|
|
out[0] = d.dt
|
|
|
|
out[1] = d.dl
|
|
|
|
out = append(out, d.dd...)
|
|
|
|
return
|
2018-12-04 08:33:04 +03:00
|
|
|
}
|
2018-12-05 14:16:06 +03:00
|
|
|
|
2018-12-05 16:34:19 +03:00
|
|
|
func (e *ESSD) Bytes() (out []byte) {
|
|
|
|
out = make([]byte, ESSDHeadLen)
|
|
|
|
out[0] = e.st
|
|
|
|
out[1] = 0xe0 | e.epid>>3
|
|
|
|
out[2] = e.epid
|
|
|
|
out[3] = 0xf0 | byte(e.esil>>6)
|
|
|
|
out[4] = byte(e.esil)
|
|
|
|
for _, d := range e.esd {
|
|
|
|
out = append(out, d.Bytes()...)
|
2018-12-05 14:16:06 +03:00
|
|
|
}
|
2018-12-05 16:34:19 +03:00
|
|
|
return
|
2018-12-05 14:16:06 +03:00
|
|
|
}
|