mirror of https://bitbucket.org/ausocean/av.git
psi: added essd data structure, isolated space check to minimise repetition
This commit is contained in:
parent
731285d665
commit
fe11ce6f08
|
@ -1,9 +1,14 @@
|
|||
package psi
|
||||
|
||||
const (
|
||||
ESSDHeadLen = 5
|
||||
DescriptorHeadLen = 2
|
||||
)
|
||||
|
||||
// Program specific information
|
||||
type PSI struct {
|
||||
pf byte // Point field
|
||||
pfb []byte // pointer filler bytes
|
||||
pfb []byte // Pointer filler bytes
|
||||
tid byte // Table ID
|
||||
ssi bool // Sectiopn syntax indicator (1 for PAT, PMT, CAT)
|
||||
pb bool // Private bit (0 for PAT, PMT, CAT)
|
||||
|
@ -18,7 +23,7 @@ type TSS struct {
|
|||
cni bool // Current/next indicator
|
||||
sn byte // Section number
|
||||
lsn byte // Last section number
|
||||
sd SD // specific data PAT/PMT
|
||||
sd SD // Specific data PAT/PMT
|
||||
crc []byte // crc32 of entire table excluding pointer field, pointer filler bytes and the trailing CRC32
|
||||
}
|
||||
|
||||
|
@ -30,34 +35,72 @@ type SD interface {
|
|||
// Program association table, implements SD
|
||||
type PAT struct {
|
||||
pn uint16 // Program Number
|
||||
pmpid uint16 // program map PID
|
||||
pmpid uint16 // Program map PID
|
||||
}
|
||||
|
||||
type Descriptor struct {
|
||||
// Program mapping table, implements SD
|
||||
type PMT struct {
|
||||
pcrpid uint16 // Program clock reference pid
|
||||
pil uint16 // Program info length
|
||||
pd []Descriptor // Program descriptors
|
||||
essd []ESSD // Elementary stream specific data
|
||||
}
|
||||
|
||||
// Elementary stream specific data
|
||||
type ESSD struct {
|
||||
st byte // Stream type
|
||||
epid byte // Elementary pid
|
||||
esil uint16 // Elementary stream
|
||||
esd []Descriptor // Elementary stream desriptors
|
||||
}
|
||||
|
||||
// Descriptor
|
||||
type Desc struct {
|
||||
dt byte // Descriptor tag
|
||||
dl byte // Descriptor length
|
||||
dd []byte // Descriptor data
|
||||
}
|
||||
|
||||
// Program mapping table, implements SD
|
||||
type PMT struct {
|
||||
pcrpid uint16 // program clock reference pid
|
||||
PIL uint16 // program info length
|
||||
PD []Descriptor // program descriptors
|
||||
}
|
||||
|
||||
func ReadPSI(data []byte) *PAT {
|
||||
func ReadPSI(data []byte) *PSI {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PSI) Bytes() (output []byte) {
|
||||
func (p *PSI) Bytes() (out []byte) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PAT) Bytes() (output []byte) {
|
||||
func (t *TSS) Fill(space []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PMT) Bytes() (output []byte) {
|
||||
func (p *PAT) Fill(space []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PMT) Fill(space []byte) error {
|
||||
checkSpace(space)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Descriptor) Fill(space []byte) error {
|
||||
checkSpace(space, DescriptorHeadLen+int(d.dl))
|
||||
space[0] = d.dt
|
||||
space[1] = d.dl
|
||||
copy(space[2:], d.dd)
|
||||
return out
|
||||
}
|
||||
|
||||
func (e *ESSD) Fill(space []byte) error {
|
||||
checkSpace(space, ESSDHeadLen+e.esil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkSpace(s []byte, c uint) {
|
||||
if s == nil {
|
||||
panic("Slice provided is nil")
|
||||
} else if len(s) != 0 {
|
||||
panic("Slice provided already has something in it")
|
||||
} else if cap(s) != c {
|
||||
panic("Slice provided has wrong capacity")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue