mirror of https://bitbucket.org/ausocean/av.git
psi: removed declaration and initialisation of standard psi structures in std.go as this is dangerous
This commit is contained in:
parent
561e603d96
commit
ffc1af2cd4
|
@ -36,6 +36,89 @@ import (
|
|||
"bitbucket.org/ausocean/av/stream/mts/psi"
|
||||
)
|
||||
|
||||
// Some common manifestations of PSI
|
||||
var (
|
||||
// PSI struct to represent basic pat
|
||||
StandardPat = psi.PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x00,
|
||||
Ssi: true,
|
||||
Pb: false,
|
||||
Sl: 0x0d,
|
||||
Tss: &psi.TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &psi.PAT{
|
||||
Pn: 0x01,
|
||||
Pmpid: 0x1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// PSI struct to represent basic pmt without descriptors for time and location
|
||||
StandardPmt = psi.PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
Sl: 0x12,
|
||||
Tss: &psi.TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &psi.PMT{
|
||||
Pcrpid: 0x0100, // wrong
|
||||
Pil: 0,
|
||||
Essd: &psi.ESSD{
|
||||
St: 0x1b,
|
||||
Epid: 0x0100,
|
||||
Esil: 0x00,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Std pmt with time and location descriptors, time and location fields are zeroed out
|
||||
StandardPmtTimeLocation = psi.PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
Sl: 0x3e,
|
||||
Tss: &psi.TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &psi.PMT{
|
||||
Pcrpid: 0x0100,
|
||||
Pil: psi.PmtTimeLocationPil,
|
||||
Pd: []psi.Desc{
|
||||
{
|
||||
Dt: psi.TimeDescTag,
|
||||
Dl: psi.TimeDataSize,
|
||||
Dd: make([]byte, psi.TimeDataSize),
|
||||
},
|
||||
{
|
||||
Dt: psi.LocationDescTag,
|
||||
Dl: psi.LocationDataSize,
|
||||
Dd: make([]byte, psi.LocationDataSize),
|
||||
},
|
||||
},
|
||||
Essd: &psi.ESSD{
|
||||
St: 0x1b,
|
||||
Epid: 0x0100,
|
||||
Esil: 0x00,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
psiPacketSize = 184
|
||||
psiSendCount = 7
|
||||
|
@ -57,8 +140,8 @@ func SetLocation(g string) {
|
|||
}
|
||||
|
||||
var (
|
||||
patTable = psi.StdPat.Bytes()
|
||||
pmtTable = psi.StdPmtTimeLocation.Bytes()
|
||||
patTable = StandardPat.Bytes()
|
||||
pmtTable = StandardPmtTimeLocation.Bytes()
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -36,7 +36,7 @@ import (
|
|||
// TimeBytes takes a timestamp as an uint64 and converts to an 8 byte slice -
|
||||
// allows for updating of timestamp in pmt time descriptor.
|
||||
func TimeBytes(t uint64) []byte {
|
||||
var s [timeDataSize]byte
|
||||
var s [TimeDataSize]byte
|
||||
binary.BigEndian.PutUint64(s[:], t)
|
||||
return s[:]
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func TimeBytes(t uint64) []byte {
|
|||
// HasTime takes a psi as a byte slice and checks to see if it has a time descriptor
|
||||
// - if so return nil, otherwise return error
|
||||
func HasTime(p []byte) bool {
|
||||
if p[timeTagIndx] == timeDescTag {
|
||||
if p[TimeTagIndx] == TimeDescTag {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -53,7 +53,7 @@ func HasTime(p []byte) bool {
|
|||
// HasLocation takes a psi as a byte slice and checks to see if it has a location descriptor
|
||||
// - if so return nil, otherwise return error
|
||||
func HasLocation(p []byte) bool {
|
||||
if p[locationTagIndx] == locationDescTag {
|
||||
if p[LocationTagIndx] == LocationDescTag {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -67,8 +67,8 @@ func UpdateTime(dst []byte, t uint64) error {
|
|||
return errors.New("pmt does not have time descriptor, cannot update")
|
||||
}
|
||||
ts := TimeBytes(uint64(t))
|
||||
for i := range dst[timeDataIndx : timeDataIndx+timeDataSize] {
|
||||
dst[i+timeDataIndx] = ts[i]
|
||||
for i := range dst[TimeDataIndx : TimeDataIndx+TimeDataSize] {
|
||||
dst[i+TimeDataIndx] = ts[i]
|
||||
}
|
||||
updateCrc(dst)
|
||||
return nil
|
||||
|
@ -81,7 +81,7 @@ func TimeFrom(p []byte) (t uint64, err error) {
|
|||
if !HasTime(p) {
|
||||
return 0, errors.New("pmt does not have a time descriptor")
|
||||
}
|
||||
t = binary.BigEndian.Uint64(p[timeDataIndx : timeDataIndx+timeDataSize])
|
||||
t = binary.BigEndian.Uint64(p[TimeDataIndx : TimeDataIndx+TimeDataSize])
|
||||
return t, nil
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func LocationFrom(p []byte) (g string, err error) {
|
|||
if !HasLocation(p) {
|
||||
return "", errors.New("pmt does not have location descriptor")
|
||||
}
|
||||
gBytes := p[locationDataIndx : locationDataIndx+locationDataSize]
|
||||
gBytes := p[LocationDataIndx : LocationDataIndx+LocationDataSize]
|
||||
gBytes = bytes.Trim(gBytes, "\x00")
|
||||
g = string(gBytes)
|
||||
return g, nil
|
||||
|
@ -101,7 +101,7 @@ func LocationFrom(p []byte) (g string, err error) {
|
|||
// LocationStrBytes take a string of location data and converts to a 32 byte slice -
|
||||
// easy update of slice representation of a pmt with location descriptor
|
||||
func LocationStrBytes(s string) []byte {
|
||||
var b [locationDataSize]byte
|
||||
var b [LocationDataSize]byte
|
||||
copy(b[:], s)
|
||||
return b[:]
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ func UpdateLocation(d []byte, s string) error {
|
|||
return errors.New("pmt does not location descriptor, cannot update")
|
||||
}
|
||||
gb := LocationStrBytes(s)
|
||||
copy(d[locationDataIndx:locationDataIndx+locationDataSize], gb)
|
||||
copy(d[LocationDataIndx:LocationDataIndx+LocationDataSize], gb)
|
||||
updateCrc(d)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -44,18 +44,18 @@ const (
|
|||
|
||||
// Consts relating to time description
|
||||
const (
|
||||
timeDescTag = 234
|
||||
timeTagIndx = 13
|
||||
timeDataIndx = 15
|
||||
timeDataSize = 8 // bytes, because time is stored in uint64
|
||||
TimeDescTag = 234
|
||||
TimeTagIndx = 13
|
||||
TimeDataIndx = 15
|
||||
TimeDataSize = 8 // bytes, because time is stored in uint64
|
||||
)
|
||||
|
||||
// Consts relating to location description
|
||||
const (
|
||||
locationDescTag = 235
|
||||
locationTagIndx = 23
|
||||
locationDataIndx = 25
|
||||
locationDataSize = 32 // bytes
|
||||
LocationDescTag = 235
|
||||
LocationTagIndx = 23
|
||||
LocationDataIndx = 25
|
||||
LocationDataSize = 32 // bytes
|
||||
)
|
||||
|
||||
// Program specific information
|
||||
|
|
|
@ -31,6 +31,89 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
// Some common manifestations of PSI
|
||||
var (
|
||||
// PSI struct to represent basic pat
|
||||
StandardPat = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x00,
|
||||
Ssi: true,
|
||||
Pb: false,
|
||||
Sl: 0x0d,
|
||||
Tss: &TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &PAT{
|
||||
Pn: 0x01,
|
||||
Pmpid: 0x1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// PSI struct to represent basic pmt without descriptors for time and location
|
||||
StandardPmt = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
Sl: 0x12,
|
||||
Tss: &TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &PMT{
|
||||
Pcrpid: 0x0100, // wrong
|
||||
Pil: 0,
|
||||
Essd: &ESSD{
|
||||
St: 0x1b,
|
||||
Epid: 0x0100,
|
||||
Esil: 0x00,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Std pmt with time and location descriptors, time and location fields are zeroed out
|
||||
StandardPmtTimeLocation = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
Sl: 0x3e,
|
||||
Tss: &TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &PMT{
|
||||
Pcrpid: 0x0100,
|
||||
Pil: PmtTimeLocationPil,
|
||||
Pd: []Desc{
|
||||
{
|
||||
Dt: TimeDescTag,
|
||||
Dl: TimeDataSize,
|
||||
Dd: make([]byte, TimeDataSize),
|
||||
},
|
||||
{
|
||||
Dt: LocationDescTag,
|
||||
Dl: LocationDataSize,
|
||||
Dd: make([]byte, LocationDataSize),
|
||||
},
|
||||
},
|
||||
Essd: &ESSD{
|
||||
St: 0x1b,
|
||||
Epid: 0x0100,
|
||||
Esil: 0x00,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// Times as ints for testing
|
||||
const (
|
||||
tstTime1 = 1235367435 // 0x49a2360b
|
||||
|
@ -60,11 +143,11 @@ var (
|
|||
var (
|
||||
pmtTimeLocationBytesPart1 = []byte{
|
||||
0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a,
|
||||
timeDescTag, // Descriptor tag for timestamp
|
||||
timeDataSize, // Length of bytes to follow
|
||||
TimeDescTag, // Descriptor tag for timestamp
|
||||
TimeDataSize, // Length of bytes to follow
|
||||
0x00, 0x00, 0x00, 0x00, 0x67, 0x6F, 0x74, 0x5F, // Timestamp data
|
||||
locationDescTag, // Descriptor tag for location
|
||||
locationDataSize, // Length of bytes to follow
|
||||
LocationDescTag, // Descriptor tag for location
|
||||
LocationDataSize, // Length of bytes to follow
|
||||
}
|
||||
pmtTimeLocationBytesPart2 = []byte{
|
||||
0x1b, 0xe1, 0x00, 0xf0, 0x00,
|
||||
|
@ -75,8 +158,8 @@ var (
|
|||
// Bytes representing pmt with tstTime1
|
||||
pmtTimeBytes1 = []byte{
|
||||
0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a,
|
||||
timeDescTag, // Descriptor tag
|
||||
timeDataSize, // Length of bytes to follow
|
||||
TimeDescTag, // Descriptor tag
|
||||
TimeDataSize, // Length of bytes to follow
|
||||
0x00, 0x00, 0x00, 0x00, 0x49, 0xA2, 0x36, 0x0B, // timestamp
|
||||
0x1b, 0xe1, 0x00, 0xf0, 0x00,
|
||||
}
|
||||
|
@ -84,8 +167,8 @@ var (
|
|||
// Bytes representing pmt with tstTime 2
|
||||
pmtTimeBytes2 = []byte{
|
||||
0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a,
|
||||
timeDescTag, // Descriptor tag
|
||||
timeDataSize, // Length of bytes to follow
|
||||
TimeDescTag, // Descriptor tag
|
||||
TimeDataSize, // Length of bytes to follow
|
||||
0x00, 0x00, 0x00, 0x00, 0x67, 0x6F, 0x74, 0x5F, // timestamp
|
||||
0x1b, 0xe1, 0x00, 0xf0, 0x00,
|
||||
}
|
||||
|
@ -136,8 +219,8 @@ var bytesTests = []struct {
|
|||
Pil: 10,
|
||||
Pd: []Desc{
|
||||
{
|
||||
Dt: timeDescTag,
|
||||
Dl: timeDataSize,
|
||||
Dt: TimeDescTag,
|
||||
Dl: TimeDataSize,
|
||||
Dd: TimeBytes(tstTime1),
|
||||
},
|
||||
},
|
||||
|
@ -171,13 +254,13 @@ var bytesTests = []struct {
|
|||
Pil: 10,
|
||||
Pd: []Desc{
|
||||
{
|
||||
Dt: timeDescTag,
|
||||
Dl: timeDataSize,
|
||||
Dt: TimeDescTag,
|
||||
Dl: TimeDataSize,
|
||||
Dd: TimeBytes(tstTime2),
|
||||
},
|
||||
{
|
||||
Dt: locationDescTag,
|
||||
Dl: locationDataSize,
|
||||
Dt: LocationDescTag,
|
||||
Dl: LocationDataSize,
|
||||
Dd: LocationStrBytes(locationTstStr1),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -27,90 +27,7 @@ LICENSE
|
|||
package psi
|
||||
|
||||
const (
|
||||
pmtTimeLocationPil = 44
|
||||
)
|
||||
|
||||
// Some common manifestations of PSI
|
||||
var (
|
||||
// PSI struct to represent basic pat
|
||||
StandardPat = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x00,
|
||||
Ssi: true,
|
||||
Pb: false,
|
||||
Sl: 0x0d,
|
||||
Tss: &TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &PAT{
|
||||
Pn: 0x01,
|
||||
Pmpid: 0x1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// PSI struct to represent basic pmt without descriptors for time and location
|
||||
StandardPmt = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
Sl: 0x12,
|
||||
Tss: &TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &PMT{
|
||||
Pcrpid: 0x0100, // wrong
|
||||
Pil: 0,
|
||||
Essd: &ESSD{
|
||||
St: 0x1b,
|
||||
Epid: 0x0100,
|
||||
Esil: 0x00,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Std pmt with time and location descriptors, time and location fields are zeroed out
|
||||
StandardPmtTimeLocation = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
Sl: 0x3e,
|
||||
Tss: &TSS{
|
||||
Tide: 0x01,
|
||||
V: 0,
|
||||
Cni: true,
|
||||
Sn: 0,
|
||||
Lsn: 0,
|
||||
Sd: &PMT{
|
||||
Pcrpid: 0x0100,
|
||||
Pil: pmtTimeLocationPil,
|
||||
Pd: []Desc{
|
||||
{
|
||||
Dt: timeDescTag,
|
||||
Dl: timeDataSize,
|
||||
Dd: make([]byte, timeDataSize),
|
||||
},
|
||||
{
|
||||
Dt: locationDescTag,
|
||||
Dl: locationDataSize,
|
||||
Dd: make([]byte, locationDataSize),
|
||||
},
|
||||
},
|
||||
Essd: &ESSD{
|
||||
St: 0x1b,
|
||||
Epid: 0x0100,
|
||||
Esil: 0x00,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
PmtTimeLocationPil = 44
|
||||
)
|
||||
|
||||
// Std PSI in bytes form
|
||||
|
|
Loading…
Reference in New Issue