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
|
||||
)
|
||||
|
||||
const TotalSyntaxSecLen = 180
|
||||
|
||||
// Consts relating to time description
|
||||
const (
|
||||
TimeDescTag = 234
|
||||
|
@ -251,8 +253,8 @@ func (p *PSIBytes) AddDescriptor(tag int, data []byte) error {
|
|||
|
||||
i, desc := p.HasDescriptor(tag)
|
||||
if desc == nil {
|
||||
p.createDescriptor(tag, data)
|
||||
return nil
|
||||
err := p.createDescriptor(tag, data)
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
// by resizing the psi, shifting existing data down and copying in new descriptor
|
||||
// in new space.
|
||||
func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
||||
func (p *PSIBytes) createDescriptor(tag int, data []byte) error {
|
||||
curProgLen := p.ProgramInfoLen()
|
||||
oldSyntaxSectionLen := SyntaxSecLenFrom(*p)
|
||||
if TotalSyntaxSecLen-(oldSyntaxSectionLen+2+len(data)) <= 0 {
|
||||
return errors.New("Not enough space in psi to create descriptor.")
|
||||
}
|
||||
dataLen := len(data)
|
||||
newDescIdx := DescriptorsIdx + curProgLen
|
||||
newDescLen := dataLen + 2
|
||||
|
@ -332,6 +337,8 @@ func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
|||
newSyntaxSectionLen := int(oldSyntaxSectionLen) + addedLen
|
||||
p.setSectionLen(newSyntaxSectionLen)
|
||||
UpdateCrc((*p)[1:])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// setProgInfoLen sets the program information length in a psi with a pmt.
|
||||
|
|
Loading…
Reference in New Issue