mirror of https://bitbucket.org/ausocean/av.git
stream/mts/discontinuity.go: fixed expectedCC logic
This commit is contained in:
parent
361f5edbc9
commit
4ddf87d63d
|
@ -34,18 +34,24 @@ import "github.com/Comcast/gots/packet"
|
||||||
// discontinuityRepairer provides function to detect discontinuities in mpegts
|
// discontinuityRepairer provides function to detect discontinuities in mpegts
|
||||||
// and set the discontinuity indicator as appropriate.
|
// and set the discontinuity indicator as appropriate.
|
||||||
type DiscontinuityRepairer struct {
|
type DiscontinuityRepairer struct {
|
||||||
expCC uint8
|
expCC map[int]int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDiscontinuityRepairer returns a pointer to a new discontinuityRepairer.
|
// NewDiscontinuityRepairer returns a pointer to a new discontinuityRepairer.
|
||||||
func NewDiscontinuityRepairer() *DiscontinuityRepairer {
|
func NewDiscontinuityRepairer() *DiscontinuityRepairer {
|
||||||
return &DiscontinuityRepairer{expCC: 16}
|
return &DiscontinuityRepairer{
|
||||||
|
expCC: map[int]int{
|
||||||
|
PatPid: 16,
|
||||||
|
PmtPid: 16,
|
||||||
|
VideoPid: 16,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failed is to be called in the case of a failed send. This will decrement the
|
// Failed is to be called in the case of a failed send. This will decrement the
|
||||||
// expectedCC so that it aligns with the failed chunks cc.
|
// expectedCC so that it aligns with the failed chunks cc.
|
||||||
func (dr *DiscontinuityRepairer) Failed() {
|
func (dr *DiscontinuityRepairer) Failed() {
|
||||||
dr.decExpectedCC()
|
dr.decExpectedCC(PatPid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repair takes a clip of mpegts and checks that the first packet, which should
|
// Repair takes a clip of mpegts and checks that the first packet, which should
|
||||||
|
@ -55,14 +61,15 @@ func (dr *DiscontinuityRepairer) Repair(d []byte) error {
|
||||||
var pkt [PacketSize]byte
|
var pkt [PacketSize]byte
|
||||||
copy(pkt[:], d[:PacketSize])
|
copy(pkt[:], d[:PacketSize])
|
||||||
p := (*packet.Packet)(&pkt)
|
p := (*packet.Packet)(&pkt)
|
||||||
if p.PID() != PatPid {
|
pid := p.PID()
|
||||||
|
if pid != PatPid {
|
||||||
panic("Clip to repair must have PAT first")
|
panic("Clip to repair must have PAT first")
|
||||||
}
|
}
|
||||||
cc := p.ContinuityCounter()
|
cc := p.ContinuityCounter()
|
||||||
expect, exists := dr.expectedCC(3)
|
expect, exists := dr.expectedCC(pid)
|
||||||
dr.incExpectedCC()
|
dr.incExpectedCC(pid)
|
||||||
if !exists {
|
if !exists {
|
||||||
dr.setExpectedCC(uint8(cc))
|
dr.setExpectedCC(pid, cc)
|
||||||
} else if cc != int(expect) {
|
} else if cc != int(expect) {
|
||||||
if packet.ContainsAdaptationField(p) {
|
if packet.ContainsAdaptationField(p) {
|
||||||
(*packet.AdaptationField)(p).SetDiscontinuity(true)
|
(*packet.AdaptationField)(p).SetDiscontinuity(true)
|
||||||
|
@ -72,7 +79,7 @@ func (dr *DiscontinuityRepairer) Repair(d []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dr.setExpectedCC(uint8(cc))
|
dr.setExpectedCC(pid, cc)
|
||||||
copy(d[:PacketSize], pkt[:])
|
copy(d[:PacketSize], pkt[:])
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -80,24 +87,24 @@ func (dr *DiscontinuityRepairer) Repair(d []byte) error {
|
||||||
|
|
||||||
// expectedCC returns the expected cc. If the cc hasn't been used yet, then 16
|
// expectedCC returns the expected cc. If the cc hasn't been used yet, then 16
|
||||||
// and false is returned.
|
// and false is returned.
|
||||||
func (dr *DiscontinuityRepairer) expectedCC(pid int) (byte, bool) {
|
func (dr *DiscontinuityRepairer) expectedCC(pid int) (int, bool) {
|
||||||
if dr.expCC == 16 {
|
if dr.expCC[pid] == 16 {
|
||||||
return 16, false
|
return 16, false
|
||||||
}
|
}
|
||||||
return dr.expCC, true
|
return dr.expCC[pid], true
|
||||||
}
|
}
|
||||||
|
|
||||||
// incExpectedCC increments the expected cc.
|
// incExpectedCC increments the expected cc.
|
||||||
func (dr *DiscontinuityRepairer) incExpectedCC() {
|
func (dr *DiscontinuityRepairer) incExpectedCC(pid int) {
|
||||||
dr.expCC = (dr.expCC + 1) & 0xf
|
dr.expCC[pid] = (dr.expCC[pid] + 1) & 0xf
|
||||||
}
|
}
|
||||||
|
|
||||||
// decExpectedCC decrements the expected cc.
|
// decExpectedCC decrements the expected cc.
|
||||||
func (dr *DiscontinuityRepairer) decExpectedCC() {
|
func (dr *DiscontinuityRepairer) decExpectedCC(pid int) {
|
||||||
dr.expCC = (dr.expCC - 1) & 0xf
|
dr.expCC[pid] = (dr.expCC[pid] - 1) & 0xf
|
||||||
}
|
}
|
||||||
|
|
||||||
// setExpectedCC sets the expected cc.
|
// setExpectedCC sets the expected cc.
|
||||||
func (dr *DiscontinuityRepairer) setExpectedCC(cc uint8) {
|
func (dr *DiscontinuityRepairer) setExpectedCC(pid, cc int) {
|
||||||
dr.expCC = cc
|
dr.expCC[pid] = cc
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue