psi: wrote bytes() for pmt

This commit is contained in:
saxon 2018-12-06 00:34:29 +10:30
parent e2a5e6a16a
commit 1fd9bed1e4
1 changed files with 24 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package psi
const ( const (
ESSDHeadLen = 5 ESSDHeadLen = 5
DescHeadLen = 2 DescHeadLen = 2
PMTHeadLen = 2
) )
// Program specific information // Program specific information
@ -49,7 +50,7 @@ type PMT struct {
// Elementary stream specific data // Elementary stream specific data
type ESSD struct { type ESSD struct {
st byte // Stream type st byte // Stream type
epid byte // Elementary pid epid uint16 // Elementary pid
esil uint16 // Elementary stream esil uint16 // Elementary stream
esd []Desc // Elementary stream desriptors esd []Desc // Elementary stream desriptors
} }
@ -75,27 +76,38 @@ func (t *TSS) Fill(s []byte) {
func (p *PAT) Fill(s []byte) { func (p *PAT) Fill(s []byte) {
} }
func (p *PMT) Bytes() (out []byte) { func (p *PMT) Bytes() []byte {
return nil out := make([]byte, PMTHeadLen)
out[0] = 0xe0 | (0x1f & byte(p.pcrpid>>8))
out[1] = byte(p.pcrpid)
out[2] = 0xf0 | (0x03 & byte(p.pil>>8))
out[3] = byte(p.pil)
for _, d := range p.pd {
out = append(out, d.Bytes()...)
}
for _, e := range p.essd {
out = append(out, e.Bytes()...)
}
return out
} }
func (d *Desc) Bytes() (out []byte) { func (d *Desc) Bytes() []byte {
out = make([]byte, DescHeadLen) out := make([]byte, DescHeadLen)
out[0] = d.dt out[0] = d.dt
out[1] = d.dl out[1] = d.dl
out = append(out, d.dd...) out = append(out, d.dd...)
return return out
} }
func (e *ESSD) Bytes() (out []byte) { func (e *ESSD) Bytes() []byte {
out = make([]byte, ESSDHeadLen) out := make([]byte, ESSDHeadLen)
out[0] = e.st out[0] = e.st
out[1] = 0xe0 | e.epid>>3 out[1] = 0xe0 | (0x1f & byte(e.epid>>8))
out[2] = e.epid out[2] = byte(e.epid)
out[3] = 0xf0 | byte(e.esil>>6) out[3] = 0xf0 | (0x03 & byte(e.esil>>8))
out[4] = byte(e.esil) out[4] = byte(e.esil)
for _, d := range e.esd { for _, d := range e.esd {
out = append(out, d.Bytes()...) out = append(out, d.Bytes()...)
} }
return return out
} }