mirror of https://bitbucket.org/ausocean/av.git
mts: add getters and setters with mutex to the TimeLocation struct.
This commit is contained in:
parent
ddf7a94ab8
commit
6cb56421d3
|
@ -30,6 +30,7 @@ package mts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"bitbucket.org/ausocean/av/stream/mts/pes"
|
"bitbucket.org/ausocean/av/stream/mts/pes"
|
||||||
|
@ -124,21 +125,46 @@ const (
|
||||||
psiSendCount = 7
|
psiSendCount = 7
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimeLocation struct {
|
// TimeLocation can hold time and location data for the insertion into mpegts
|
||||||
Time uint64
|
// packets.
|
||||||
Location string
|
type timeLocation struct {
|
||||||
|
sync.RWMutex
|
||||||
|
time uint64
|
||||||
|
location string
|
||||||
}
|
}
|
||||||
|
|
||||||
var metaData = TimeLocation{}
|
// SetTimeStamp sets the time field of a TimeLocation.
|
||||||
|
func (tl *timeLocation) SetTimeStamp(t uint64) {
|
||||||
func SetTimeStamp(t uint64) {
|
tl.Lock()
|
||||||
metaData.Time = t
|
tl.time = t
|
||||||
|
tl.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetLocation(g string) {
|
// GetTimeStamp returns the location of a TimeLocation.
|
||||||
metaData.Location = g
|
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 (
|
var (
|
||||||
patTable = standardPat.Bytes()
|
patTable = standardPat.Bytes()
|
||||||
pmtTable = standardPmtTimeLocation.Bytes()
|
pmtTable = standardPmtTimeLocation.Bytes()
|
||||||
|
@ -269,11 +295,11 @@ func (e *Encoder) writePSI() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update pmt table time and location.
|
// Update pmt table time and location.
|
||||||
err = psi.UpdateTime(pmtTable, metaData.Time)
|
err = psi.UpdateTime(pmtTable, MetaData.GetTimeStamp())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = psi.UpdateLocation(pmtTable, metaData.Location)
|
err = psi.UpdateLocation(pmtTable, MetaData.GetLocation())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue