diff --git a/stream/mts/psi/descriptor_test.go b/stream/mts/psi/descriptor_test.go index d11053d1..b26fd007 100644 --- a/stream/mts/psi/descriptor_test.go +++ b/stream/mts/psi/descriptor_test.go @@ -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()) diff --git a/stream/mts/psi/psi.go b/stream/mts/psi/psi.go index 7c7e150b..c41e1d98 100644 --- a/stream/mts/psi/psi.go +++ b/stream/mts/psi/psi.go @@ -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.