av/stream/mts/psi/op.go

44 lines
757 B
Go
Raw Normal View History

2018-12-11 09:46:26 +03:00
package psi
import (
"encoding/binary"
"errors"
)
func TimeToBytes(time uint64) []byte {
s := make([]byte, 8)
binary.BigEndian.PutUint64(s, time)
return s
}
func chkTime(d []byte) error {
if d[descTagIndx] != timeDescTag {
return errors.New("PSI does not contain a time descriptor, cannot update")
}
return nil
}
// Updatetime
func UpdateTime(d []byte, t int) error {
err := chkTime(d)
if err != nil {
return err
}
ts := TimeToBytes(uint64(t))
for i := range d[timeIndx : timeIndx+8] {
d[i+timeIndx] = ts[i]
}
return nil
}
func TimeOf(d []byte) (t uint64, err error) {
err = chkTime(d)
if err != nil {
return 0, err
}
for i := range d[timeIndx : timeIndx+8] {
t |= uint64(d[i+timeIndx]) << uint(56-i*8)
}
return t, nil
}