From 7c6719ab5afba4ba9daaf1f5053840096a33d368 Mon Sep 17 00:00:00 2001 From: Saxon Date: Sat, 2 Mar 2019 13:15:18 +1030 Subject: [PATCH] stream/mts: using packet.Packet straight away and not doing unnecessary conversions --- stream/mts/discontinuity.go | 11 +++++------ stream/mts/mpegts.go | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/stream/mts/discontinuity.go b/stream/mts/discontinuity.go index 68905bd4..adccebad 100644 --- a/stream/mts/discontinuity.go +++ b/stream/mts/discontinuity.go @@ -60,18 +60,17 @@ func (dr *DiscontinuityRepairer) Failed() { // be a PAT, contains a cc that is expected, otherwise the discontinuity indicator // is set to true. func (dr *DiscontinuityRepairer) Repair(d []byte) error { - var pkt [PacketSize]byte + var pkt packet.Packet copy(pkt[:], d[:PacketSize]) - p := (*packet.Packet)(&pkt) - pid := p.PID() + pid := pkt.PID() if pid != PatPid { panic("Clip to repair must have PAT first") } - cc := p.ContinuityCounter() + cc := pkt.ContinuityCounter() expect, _ := dr.ExpectedCC(pid) if cc != int(expect) { - if packet.ContainsAdaptationField(p) { - (*packet.AdaptationField)(p).SetDiscontinuity(true) + if packet.ContainsAdaptationField(&pkt) { + (*packet.AdaptationField)(&pkt).SetDiscontinuity(true) } else { err := addAdaptationField(&pkt, DiscontinuityIndicator(true)) if err != nil { diff --git a/stream/mts/mpegts.go b/stream/mts/mpegts.go index ea36c474..a3908659 100644 --- a/stream/mts/mpegts.go +++ b/stream/mts/mpegts.go @@ -263,11 +263,11 @@ func (p *Packet) Bytes(buf []byte) []byte { return buf } -type Option func(p *[PacketSize]byte) +type Option func(p *packet.Packet) // addAdaptationField adds an adaptation field to p, and applys the passed options to this field. // TODO: this will probably break if we already have adaptation field. -func addAdaptationField(p *[PacketSize]byte, options ...Option) error { +func addAdaptationField(p *packet.Packet, options ...Option) error { if packet.ContainsAdaptationField((*packet.Packet)(p)) { return errors.New("Adaptation field is already present in packet") } @@ -290,7 +290,7 @@ func addAdaptationField(p *[PacketSize]byte, options ...Option) error { // resetAdaptation sets fields in ps adaptation field to 0 if the adaptation field // exists, otherwise an error is returned. -func resetAdaptation(p *[PacketSize]byte) error { +func resetAdaptation(p *packet.Packet) error { if !packet.ContainsAdaptationField((*packet.Packet)(p)) { return errors.New("No adaptation field in this packet") } @@ -302,7 +302,7 @@ func resetAdaptation(p *[PacketSize]byte) error { // DiscontinuityIndicator returns and Option that will set p's discontinuity // indicator according to f. func DiscontinuityIndicator(f bool) Option { - return func(p *[PacketSize]byte) { + return func(p *packet.Packet) { set := byte(DiscontinuityIndicatorMask) if !f { set = 0x00