From 281aa47fd5a61c8c182af1b7075a88f0a91c1a17 Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 16 Feb 2019 01:40:35 +1030 Subject: [PATCH] stream/mts: fixing discontinuities that could be caused by ringbuffer --- revid/mtsSender_test.go | 39 +++++++++++++++++++++++++++++++++++++ revid/senders.go | 20 +++++++++++++++++++ stream/mts/discontinuity.go | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 revid/mtsSender_test.go diff --git a/revid/mtsSender_test.go b/revid/mtsSender_test.go new file mode 100644 index 00000000..8c925b8d --- /dev/null +++ b/revid/mtsSender_test.go @@ -0,0 +1,39 @@ +/* +NAME + mtsSender_test.go + +DESCRIPTION + mtsSender_test.go contains tests that validate the functionalilty of the + mtsSender under senders.go. Tests include checks that the mtsSender is + segmenting sends correctly, and also that it can correct discontinuities. + +AUTHORS + Saxon A. Nelson-Milton + +LICENSE + mtsSender_test.go is Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean) + + It is free software: you can redistribute it and/or modify them + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. +*/ +package revid + +import "testing" + +func TestSegment(t *testing.T) { + +} + +func TestDiscontinuity(t *testing.T) { + +} diff --git a/revid/senders.go b/revid/senders.go index 65374fd2..6018ad97 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -114,6 +114,7 @@ type mtsSender struct { buf []byte pkt [mts.PacketSize]byte fail bool + discard bool repairer *mts.DiscontinuityRepairer chunk *ring.Chunk } @@ -136,6 +137,25 @@ func (s *mtsSender) load(c *ring.Chunk) error { // in s.buf is sent, otherwise the packet is added to s.buf. func (s *mtsSender) send() error { copy(s.pkt[:], s.chunk.Bytes()) + p := (*packet.Packet)(&s.pkt) + pid := p.PID() + cc := p.ContinuityCounter() + + if s.discard { + if pid != mts.PatPid { + return nil + } + s.discard = false + } + + if pid == mts.VideoPid { + if cc != s.repairer.expectedCC(pid) { + s.discard = true + s.buf = s.buf[:0] + return nil + } + } + if s.fail || (((*packet.Packet)(&s.pkt)).PID() == mts.PatPid && len(s.buf) != 0) { err := s.fixAndSend() if err != nil { diff --git a/stream/mts/discontinuity.go b/stream/mts/discontinuity.go index 5187dcb8..ff122032 100644 --- a/stream/mts/discontinuity.go +++ b/stream/mts/discontinuity.go @@ -80,7 +80,7 @@ func (dr *DiscontinuityRepairer) Repair(d []byte) error { // expectedCC returns the expected cc. If the cc hasn't been used yet, then 16 // and false is returned. -func (dr *DiscontinuityRepairer) expectedCC() (byte, bool) { +func (dr *DiscontinuityRepairer) expectedCC(pid int) (byte, bool) { if dr.expCC == 16 { return 16, false }