stream/mts/psi: modified way in which we add padding to psi - now we leave it up to the mts package to do this on creation of an ts packet. Also in the middle of writing AddDescriptor func, and finding issues, hence the mentioned change.

This commit is contained in:
saxon 2019-01-29 15:42:51 +10:30
parent 2145db71d4
commit 252e6680ed
2 changed files with 29 additions and 27 deletions

View File

@ -168,6 +168,10 @@ func TestProgramInfoLen(t *testing.T) {
}
}
func TestSectionLen(t *testing.T) {
}
func TestDescriptors(t *testing.T) {
// Try psi with descriptors
p := PSIBytes(tstPsi1.Bytes())

View File

@ -26,12 +26,6 @@ LICENSE
package psi
import (
"errors"
"github.com/Comcast/gots/psi"
)
const (
PacketSize = 184 // packet size of a psi.
)
@ -170,7 +164,6 @@ func (p *PSI) Bytes() []byte {
out[3] = byte(p.Sl)
out = append(out, p.Tss.Bytes()...)
out = addCrc(out)
out = addPadding(out)
return out
}
@ -241,29 +234,31 @@ func asByte(b bool) byte {
}
func (p *PSIBytes) AddDescriptor(tag int, data []byte) error {
if psi.TableID(*p) != pmtID {
return errors.New("trying to add descriptor, but not pmt")
}
/*
if psi.TableID(*p) != pmtID {
return errors.New("trying to add descriptor, but not pmt")
}
i, desc := p.HasDescriptor(tag)
if desc == nil {
p.createDescriptor(tag, data)
return nil
}
oldDescLen := desc.len()
// update the descriptor
oldDataLen := int(desc[1])
newDataLen := len(data)
newDescLen := 2 + newDataLen
i, desc := p.HasDescriptor(tag)
if desc == nil {
p.createDescriptor(tag, data)
return nil
}
oldDescLen := desc.len()
// update the descriptor
oldDataLen := int(desc[1])
newDataLen := len(data)
newDescLen := 2 + newDataLen
// Shift data
copy(p[i+newDescLen:], data)
// Shift data
// copy(p[i+newDescLen:], data)
deltaLen := desc.len() - oldDescLen
newProgInfoLen := p.ProgramInfoLen() + deltaLen
p.SetProgInfoLen(newProgInfoLen)
newSectionLen := int(psi.SectionLength(*p)) + deltaLen
p.SetSectionLen(newSectionLen)
deltaLen := desc.len() - oldDescLen
newProgInfoLen := p.ProgramInfoLen() + deltaLen
p.SetProgInfoLen(newProgInfoLen)
newSectionLen := int(psi.SectionLength(*p)) + deltaLen
p.SetSectionLen(newSectionLen)
*/
return nil
}
@ -302,6 +297,9 @@ func (p *PSIBytes) createDescriptor(tag int, data []byte) {
newDescLen := dataLen + 2
// Copy data down from newDescIdx to create room for the new descriptor.
tmp := make([]byte, len(*p)+newDescLen)
copy(tmp, *p)
*p = tmp
copy((*p)[newDescIdx+newDescLen:], (*p)[newDescIdx:newDescIdx+newDescLen])
// Set the tag, data len and data of the new desriptor.