mirror of https://bitbucket.org/ausocean/av.git
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:
parent
2145db71d4
commit
252e6680ed
|
@ -168,6 +168,10 @@ func TestProgramInfoLen(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSectionLen(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestDescriptors(t *testing.T) {
|
func TestDescriptors(t *testing.T) {
|
||||||
// Try psi with descriptors
|
// Try psi with descriptors
|
||||||
p := PSIBytes(tstPsi1.Bytes())
|
p := PSIBytes(tstPsi1.Bytes())
|
||||||
|
|
|
@ -26,12 +26,6 @@ LICENSE
|
||||||
|
|
||||||
package psi
|
package psi
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/Comcast/gots/psi"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PacketSize = 184 // packet size of a psi.
|
PacketSize = 184 // packet size of a psi.
|
||||||
)
|
)
|
||||||
|
@ -170,7 +164,6 @@ func (p *PSI) Bytes() []byte {
|
||||||
out[3] = byte(p.Sl)
|
out[3] = byte(p.Sl)
|
||||||
out = append(out, p.Tss.Bytes()...)
|
out = append(out, p.Tss.Bytes()...)
|
||||||
out = addCrc(out)
|
out = addCrc(out)
|
||||||
out = addPadding(out)
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,29 +234,31 @@ func asByte(b bool) byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PSIBytes) AddDescriptor(tag int, data []byte) error {
|
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)
|
i, desc := p.HasDescriptor(tag)
|
||||||
if desc == nil {
|
if desc == nil {
|
||||||
p.createDescriptor(tag, data)
|
p.createDescriptor(tag, data)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
oldDescLen := desc.len()
|
oldDescLen := desc.len()
|
||||||
// update the descriptor
|
// update the descriptor
|
||||||
oldDataLen := int(desc[1])
|
oldDataLen := int(desc[1])
|
||||||
newDataLen := len(data)
|
newDataLen := len(data)
|
||||||
newDescLen := 2 + newDataLen
|
newDescLen := 2 + newDataLen
|
||||||
|
|
||||||
// Shift data
|
// Shift data
|
||||||
copy(p[i+newDescLen:], data)
|
// copy(p[i+newDescLen:], data)
|
||||||
|
|
||||||
deltaLen := desc.len() - oldDescLen
|
deltaLen := desc.len() - oldDescLen
|
||||||
newProgInfoLen := p.ProgramInfoLen() + deltaLen
|
newProgInfoLen := p.ProgramInfoLen() + deltaLen
|
||||||
p.SetProgInfoLen(newProgInfoLen)
|
p.SetProgInfoLen(newProgInfoLen)
|
||||||
newSectionLen := int(psi.SectionLength(*p)) + deltaLen
|
newSectionLen := int(psi.SectionLength(*p)) + deltaLen
|
||||||
p.SetSectionLen(newSectionLen)
|
p.SetSectionLen(newSectionLen)
|
||||||
|
*/
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,6 +297,9 @@ func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
||||||
newDescLen := dataLen + 2
|
newDescLen := dataLen + 2
|
||||||
|
|
||||||
// Copy data down from newDescIdx to create room for the new descriptor.
|
// 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])
|
copy((*p)[newDescIdx+newDescLen:], (*p)[newDescIdx:newDescIdx+newDescLen])
|
||||||
|
|
||||||
// Set the tag, data len and data of the new desriptor.
|
// Set the tag, data len and data of the new desriptor.
|
||||||
|
|
Loading…
Reference in New Issue