mirror of https://bitbucket.org/ausocean/av.git
psi: wrote Bytes() for TSS and almost done writing for PSI
This commit is contained in:
parent
fa0498bc52
commit
42038a8cb9
|
@ -5,6 +5,8 @@ const (
|
|||
DescDefLen = 2
|
||||
PMTDefLen = 4
|
||||
PATLen = 4
|
||||
TSSDefLen = 5
|
||||
PSIDefLen = 3
|
||||
)
|
||||
|
||||
// Program specific information
|
||||
|
@ -16,17 +18,17 @@ type PSI struct {
|
|||
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
|
||||
crc uint32 // crc32 of entire table excluding pointer field, pointer filler bytes and the trailing CRC32
|
||||
}
|
||||
|
||||
// Table syntax section
|
||||
type TSS struct {
|
||||
tie uint16 // Table ID extension
|
||||
tide uint16 // Table ID extension
|
||||
v byte // Version number
|
||||
cni bool // Current/next indicator
|
||||
sn byte // Section number
|
||||
lsn byte // Last section number
|
||||
sd SD // Specific data PAT/PMT
|
||||
crc []byte // crc32 of entire table excluding pointer field, pointer filler bytes and the trailing CRC32
|
||||
}
|
||||
|
||||
// Specific Data, (could be PAT or PMT)
|
||||
|
@ -63,15 +65,35 @@ type Desc struct {
|
|||
dd []byte // Descriptor data
|
||||
}
|
||||
|
||||
// TODO: Implement this
|
||||
func ReadPSI(data []byte) *PSI {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PSI) Bytes() (out []byte) {
|
||||
func (p *PSI) Bytes() []byte {
|
||||
l := 1 + len(p.pfb)
|
||||
out := make([]byte, l+PSIDefLen)
|
||||
out[0] = p.pf
|
||||
for i, b := range p.pfb {
|
||||
out[1+i] = b
|
||||
}
|
||||
out[l] = p.tid
|
||||
out[l+1] = 0x80 | 0x40 | 0x30 | (0x03 & byte(p.sl>>8))
|
||||
out[l+2] = byte(p.sl)
|
||||
out = append(out, p.tss.Bytes()...)
|
||||
crc32 := crc32_op()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TSS) Fill(s []byte) {
|
||||
func (t *TSS) Bytes() []byte {
|
||||
out := make([]byte, TSSDefLen)
|
||||
out[0] = byte(t.tide >> 8)
|
||||
out[1] = byte(t.tide)
|
||||
out[2] = 0xc0 | (0x3e & (t.v << 1)) | (0x01 & boolToByte(t.cni))
|
||||
out[3] = t.sn
|
||||
out[4] = t.lsn
|
||||
out = append(out, t.sd.Bytes()...)
|
||||
return out
|
||||
}
|
||||
|
||||
func (p *PAT) Bytes() []byte {
|
||||
|
@ -118,3 +140,10 @@ func (e *ESSD) Bytes() []byte {
|
|||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func boolToByte(b bool) byte {
|
||||
if b {
|
||||
return 0x01
|
||||
}
|
||||
return 0x00
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue