mirror of https://bitbucket.org/ausocean/av.git
mts: add function for converting byte slice to packet.Packet
This commit is contained in:
parent
86e88c0f43
commit
ed40392bb5
|
@ -31,6 +31,7 @@ package mts
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/Comcast/gots/packet"
|
||||
gotspsi "github.com/Comcast/gots/psi"
|
||||
|
@ -374,6 +375,15 @@ func asByte(b bool) byte {
|
|||
return 0
|
||||
}
|
||||
|
||||
// GotsPacket takes a byte slice and returns a Packet as defined in github.com/comcast/gots/packet.
|
||||
// TODO: replace this with a type conversion as described here: https://github.com/golang/go/issues/395
|
||||
func GotsPacket(b []byte) *packet.Packet {
|
||||
if len(b) != packet.PacketSize {
|
||||
panic("invalid packet size")
|
||||
}
|
||||
return *(**packet.Packet)(unsafe.Pointer(&b))
|
||||
}
|
||||
|
||||
type Option func(p *packet.Packet)
|
||||
|
||||
// addAdaptationField adds an adaptation field to p, and applys the passed options to this field.
|
||||
|
|
|
@ -768,3 +768,12 @@ func TestFindPSI(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGotsPacket(t *testing.T) {
|
||||
b := make([]byte, 188)
|
||||
p := GotsPacket(b)
|
||||
p.SetPID(PIDAudio)
|
||||
if p.PID() != PIDAudio {
|
||||
t.Error("failed to set PID in gots Packet")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue