mirror of https://bitbucket.org/ausocean/av.git
stream/mts: fixing discontinuities that could be caused by ringbuffer
This commit is contained in:
parent
bea0000340
commit
281aa47fd5
|
@ -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 <saxon@ausocean.org>
|
||||
|
||||
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) {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue