stream/mts: using packet.Packet straight away and not doing unnecessary conversions

This commit is contained in:
Saxon 2019-03-02 13:15:18 +10:30
parent 5dd3045db2
commit 7c6719ab5a
2 changed files with 9 additions and 10 deletions

View File

@ -60,18 +60,17 @@ func (dr *DiscontinuityRepairer) Failed() {
// be a PAT, contains a cc that is expected, otherwise the discontinuity indicator // be a PAT, contains a cc that is expected, otherwise the discontinuity indicator
// is set to true. // is set to true.
func (dr *DiscontinuityRepairer) Repair(d []byte) error { func (dr *DiscontinuityRepairer) Repair(d []byte) error {
var pkt [PacketSize]byte var pkt packet.Packet
copy(pkt[:], d[:PacketSize]) copy(pkt[:], d[:PacketSize])
p := (*packet.Packet)(&pkt) pid := pkt.PID()
pid := p.PID()
if pid != PatPid { if pid != PatPid {
panic("Clip to repair must have PAT first") panic("Clip to repair must have PAT first")
} }
cc := p.ContinuityCounter() cc := pkt.ContinuityCounter()
expect, _ := dr.ExpectedCC(pid) expect, _ := dr.ExpectedCC(pid)
if cc != int(expect) { if cc != int(expect) {
if packet.ContainsAdaptationField(p) { if packet.ContainsAdaptationField(&pkt) {
(*packet.AdaptationField)(p).SetDiscontinuity(true) (*packet.AdaptationField)(&pkt).SetDiscontinuity(true)
} else { } else {
err := addAdaptationField(&pkt, DiscontinuityIndicator(true)) err := addAdaptationField(&pkt, DiscontinuityIndicator(true))
if err != nil { if err != nil {

View File

@ -263,11 +263,11 @@ func (p *Packet) Bytes(buf []byte) []byte {
return buf 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. // 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. // 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)) { if packet.ContainsAdaptationField((*packet.Packet)(p)) {
return errors.New("Adaptation field is already present in packet") 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 // resetAdaptation sets fields in ps adaptation field to 0 if the adaptation field
// exists, otherwise an error is returned. // exists, otherwise an error is returned.
func resetAdaptation(p *[PacketSize]byte) error { func resetAdaptation(p *packet.Packet) error {
if !packet.ContainsAdaptationField((*packet.Packet)(p)) { if !packet.ContainsAdaptationField((*packet.Packet)(p)) {
return errors.New("No adaptation field in this packet") 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 // DiscontinuityIndicator returns and Option that will set p's discontinuity
// indicator according to f. // indicator according to f.
func DiscontinuityIndicator(f bool) Option { func DiscontinuityIndicator(f bool) Option {
return func(p *[PacketSize]byte) { return func(p *packet.Packet) {
set := byte(DiscontinuityIndicatorMask) set := byte(DiscontinuityIndicatorMask)
if !f { if !f {
set = 0x00 set = 0x00