From 252e6680ed16e1885a22fdc3b797f34b844d78fa Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 29 Jan 2019 15:42:51 +1030 Subject: [PATCH] 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. --- stream/mts/psi/descriptor_test.go | 4 +++ stream/mts/psi/psi.go | 52 +++++++++++++++---------------- 2 files changed, 29 insertions(+), 27 deletions(-) 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.