mirror of https://bitbucket.org/ausocean/av.git
stream/mts: using packet.Packet straight away and not doing unnecessary conversions
This commit is contained in:
parent
5dd3045db2
commit
7c6719ab5a
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue