mirror of https://bitbucket.org/ausocean/av.git
stream/mts/psi: changed HasDescriptor to also return index of descriptor in psi. Wrote func called SetProgInfoLen to set the program info length in a pmt. Started writing deleteDescriptor func to get rid of a descriptor.
This commit is contained in:
parent
a61bdac2de
commit
4a3464252b
|
@ -128,7 +128,7 @@ func TestHasDescriptor(t *testing.T) {
|
|||
p := PSIBytes(tstPsi3.Bytes())
|
||||
|
||||
// Try getting descriptor that exists
|
||||
got := p.HasDescriptor(LocationDescTag)
|
||||
_, got := p.HasDescriptor(LocationDescTag)
|
||||
want := []byte{
|
||||
LocationDescTag,
|
||||
LocationDataSize,
|
||||
|
@ -141,7 +141,7 @@ func TestHasDescriptor(t *testing.T) {
|
|||
|
||||
// Try getting descriptor that doesnt exist
|
||||
const fakeTag = 236
|
||||
got = p.HasDescriptor(fakeTag)
|
||||
_, got = p.HasDescriptor(fakeTag)
|
||||
want = nil
|
||||
|
||||
if !bytes.Equal(got, want) {
|
||||
|
@ -151,7 +151,7 @@ func TestHasDescriptor(t *testing.T) {
|
|||
// Try getting descriptor from psi that has no descriptors
|
||||
p = PSIBytes(tstPsi2.Bytes())
|
||||
|
||||
got = p.HasDescriptor(LocationDescTag)
|
||||
_, got = p.HasDescriptor(LocationDescTag)
|
||||
want = nil
|
||||
|
||||
if !bytes.Equal(got, want) {
|
||||
|
@ -219,6 +219,10 @@ func TestCreateDescriptor(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDeleteDescriptor(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestUpdateDescriptor(t *testing.T) {
|
||||
|
||||
}
|
||||
|
|
|
@ -245,7 +245,7 @@ func (p *PSIBytes) AddDescriptor(tag int, data []byte) error {
|
|||
return errors.New("trying to add descriptor, but not pmt")
|
||||
}
|
||||
|
||||
desc := p.HasDescriptor(tag)
|
||||
_, desc := p.HasDescriptor(tag)
|
||||
if desc == nil {
|
||||
p.createDescriptor(tag, data)
|
||||
return nil
|
||||
|
@ -258,17 +258,17 @@ func (p *PSIBytes) ProgramInfoLen() int {
|
|||
return int((((*p)[ProgramInfoLenIdx1] & ProgramInfoLenMask1) << 8) | (*p)[ProgramInfoLenIdx2])
|
||||
}
|
||||
|
||||
func (p *PSIBytes) HasDescriptor(tag int) Descriptor {
|
||||
func (p *PSIBytes) HasDescriptor(tag int) (int, Descriptor) {
|
||||
descs := p.descriptors()
|
||||
if descs == nil {
|
||||
return nil
|
||||
return -1, nil
|
||||
}
|
||||
for i := 0; i < len(descs); i += 2 + int(descs[i+1]) {
|
||||
if int(descs[i]) == tag {
|
||||
return descs[i : i+2+int(descs[i+1])]
|
||||
return i, descs[i : i+2+int(descs[i+1])]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
func (p *PSIBytes) descriptors() []byte {
|
||||
|
@ -283,8 +283,10 @@ func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
|||
// Calculate the new descriptors index and length.
|
||||
newDescIdx := DescriptorsIdx + curProgLen
|
||||
newDescLen := dataLen + 2
|
||||
|
||||
// Copy data down from newDescIdx to create room for the new descriptor.
|
||||
copy((*p)[newDescIdx+newDescLen:], (*p)[newDescIdx:newDescIdx+newDescLen])
|
||||
|
||||
// Set the tag, data len and data of the new desriptor.
|
||||
(*p)[newDescIdx] = byte(tag)
|
||||
(*p)[newDescIdx+1] = byte(dataLen)
|
||||
|
@ -294,9 +296,7 @@ func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
|||
// TODO: put this in function set program info length
|
||||
addedLen := dataLen + 2
|
||||
newProgInfoLen := curProgLen + addedLen
|
||||
(*p)[ProgramInfoLenIdx1] &= 0xff ^ ProgramInfoLenMask1
|
||||
(*p)[ProgramInfoLenIdx1] |= byte(newProgInfoLen>>8) & ProgramInfoLenMask1
|
||||
(*p)[ProgramInfoLenIdx2] = byte(newProgInfoLen)
|
||||
p.SetProgInfoLen(newProgInfoLen)
|
||||
|
||||
// set section length
|
||||
// TODO: put this in func set program info length
|
||||
|
@ -306,6 +306,7 @@ func (p *PSIBytes) createDescriptor(tag int, data []byte) {
|
|||
(*p)[SyntaxSecLenIdx2] = byte(newSyntaxSectionLen)
|
||||
}
|
||||
|
||||
// TODO: make this safer. If no padding, does this index out of range ?
|
||||
func (p *PSIBytes) trimPadding() []byte {
|
||||
sectionLength := SyntaxSecLenFrom(*p)
|
||||
paddingIdx := (4 + sectionLength)
|
||||
|
@ -313,6 +314,22 @@ func (p *PSIBytes) trimPadding() []byte {
|
|||
return o
|
||||
}
|
||||
|
||||
func (p *PSIBytes) SetProgInfoLen(l int) {
|
||||
// TODO: check if pmt first
|
||||
(*p)[ProgramInfoLenIdx1] &= 0xff ^ ProgramInfoLenMask1
|
||||
(*p)[ProgramInfoLenIdx1] |= byte(l>>8) & ProgramInfoLenMask1
|
||||
(*p)[ProgramInfoLenIdx2] = byte(l)
|
||||
}
|
||||
|
||||
func (p *PSIBytes) deleteDescriptor(tag int) error {
|
||||
if i, desc := p.HasDescriptor(tag); desc != nil {
|
||||
descLen := len(desc)
|
||||
newProgInfoLen := p.ProgramInfoLen() - descLen
|
||||
p.SetProgInfoLen(newProgInfoLen)
|
||||
}
|
||||
return errors.New("Descriptor doesn't exist")
|
||||
}
|
||||
|
||||
func (d *Descriptor) update(data []byte) {
|
||||
if len(data) > int((*d)[1]) {
|
||||
// TODO: implement resizing of descriptor
|
||||
|
|
Loading…
Reference in New Issue