mts: add getters and setters with mutex to the TimeLocation struct.

This commit is contained in:
saxon 2019-01-08 20:01:30 +10:30
parent ddf7a94ab8
commit 6cb56421d3
1 changed files with 37 additions and 11 deletions

View File

@ -30,6 +30,7 @@ package mts
import (
"io"
"sync"
"time"
"bitbucket.org/ausocean/av/stream/mts/pes"
@ -124,21 +125,46 @@ const (
psiSendCount = 7
)
type TimeLocation struct {
Time uint64
Location string
// TimeLocation can hold time and location data for the insertion into mpegts
// packets.
type timeLocation struct {
sync.RWMutex
time uint64
location string
}
var metaData = TimeLocation{}
func SetTimeStamp(t uint64) {
metaData.Time = t
// SetTimeStamp sets the time field of a TimeLocation.
func (tl *timeLocation) SetTimeStamp(t uint64) {
tl.Lock()
tl.time = t
tl.Unlock()
}
func SetLocation(g string) {
metaData.Location = g
// GetTimeStamp returns the location of a TimeLocation.
func (tl *timeLocation) GetTimeStamp() uint64 {
tl.RLock()
defer tl.RUnlock()
return tl.time
}
// SetLocation sets the location of a TimeLocation.
func (tl *timeLocation) SetLocation(l string) {
tl.Lock()
tl.location = l
tl.Unlock()
}
// GetLocation returns the location of a TimeLocation.
func (tl *timeLocation) GetLocation() string {
tl.RLock()
defer tl.RUnlock()
return tl.location
}
// MetData will hold time and location data which may be set externally if
// this data is available. It is then inserted into mpegts packets outputted.
var MetaData timeLocation
var (
patTable = standardPat.Bytes()
pmtTable = standardPmtTimeLocation.Bytes()
@ -269,11 +295,11 @@ func (e *Encoder) writePSI() error {
}
// Update pmt table time and location.
err = psi.UpdateTime(pmtTable, metaData.Time)
err = psi.UpdateTime(pmtTable, MetaData.GetTimeStamp())
if err != nil {
return err
}
err = psi.UpdateLocation(pmtTable, metaData.Location)
err = psi.UpdateLocation(pmtTable, MetaData.GetLocation())
if err != nil {
return nil
}