mirror of https://bitbucket.org/ausocean/av.git
stream/mts/psi/psi.go: checking that we have enough space in psi before creating descriptor
This commit is contained in:
parent
21265303d7
commit
b4393e5136
|
@ -52,6 +52,8 @@ const (
|
||||||
pmtID = 0x02
|
pmtID = 0x02
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const TotalSyntaxSecLen = 180
|
||||||
|
|
||||||
// Consts relating to time description
|
// Consts relating to time description
|
||||||
const (
|
const (
|
||||||
TimeDescTag = 234
|
TimeDescTag = 234
|
||||||
|
@ -251,8 +253,8 @@ func (p *PSIBytes) AddDescriptor(tag int, data []byte) error {
|
||||||
|
|
||||||
i, desc := p.HasDescriptor(tag)
|
i, desc := p.HasDescriptor(tag)
|
||||||
if desc == nil {
|
if desc == nil {
|
||||||
p.createDescriptor(tag, data)
|
err := p.createDescriptor(tag, data)
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
oldDescLen := desc.len()
|
oldDescLen := desc.len()
|
||||||
|
@ -308,9 +310,12 @@ func (p *PSIBytes) HasDescriptor(tag int) (int, Descriptor) {
|
||||||
// createDescriptor creates a descriptor in a psi given a tag and data. It does so
|
// createDescriptor creates a descriptor in a psi given a tag and data. It does so
|
||||||
// by resizing the psi, shifting existing data down and copying in new descriptor
|
// by resizing the psi, shifting existing data down and copying in new descriptor
|
||||||
// in new space.
|
// in new space.
|
||||||
func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
func (p *PSIBytes) createDescriptor(tag int, data []byte) error {
|
||||||
curProgLen := p.ProgramInfoLen()
|
curProgLen := p.ProgramInfoLen()
|
||||||
oldSyntaxSectionLen := SyntaxSecLenFrom(*p)
|
oldSyntaxSectionLen := SyntaxSecLenFrom(*p)
|
||||||
|
if TotalSyntaxSecLen-(oldSyntaxSectionLen+2+len(data)) <= 0 {
|
||||||
|
return errors.New("Not enough space in psi to create descriptor.")
|
||||||
|
}
|
||||||
dataLen := len(data)
|
dataLen := len(data)
|
||||||
newDescIdx := DescriptorsIdx + curProgLen
|
newDescIdx := DescriptorsIdx + curProgLen
|
||||||
newDescLen := dataLen + 2
|
newDescLen := dataLen + 2
|
||||||
|
@ -332,6 +337,8 @@ func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
||||||
newSyntaxSectionLen := int(oldSyntaxSectionLen) + addedLen
|
newSyntaxSectionLen := int(oldSyntaxSectionLen) + addedLen
|
||||||
p.setSectionLen(newSyntaxSectionLen)
|
p.setSectionLen(newSyntaxSectionLen)
|
||||||
UpdateCrc((*p)[1:])
|
UpdateCrc((*p)[1:])
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setProgInfoLen sets the program information length in a psi with a pmt.
|
// setProgInfoLen sets the program information length in a psi with a pmt.
|
||||||
|
|
Loading…
Reference in New Issue