generator: clean up time

This commit is contained in:
Dan Kortschak 2018-08-18 13:21:50 +09:30
parent 15d2fc6afe
commit 1fb325314d
1 changed files with 12 additions and 9 deletions

View File

@ -29,6 +29,8 @@ LICENSE
package generator
import (
"time"
"bitbucket.org/ausocean/av/mpegts"
"bitbucket.org/ausocean/av/pes"
)
@ -56,7 +58,8 @@ const (
pmtPid = 4096
videoPid = 256
streamID = 0xe0
ptsOffset = 0.7
ptsOffset = 700 * time.Millisecond
ptsFreq = 90000 // Hz
maxCC = 0xf
)
@ -64,9 +67,9 @@ const (
type tsGenerator struct {
outputChan chan []byte
nalInputChan chan []byte
currentPtsTime float64
currentPcrTime float64
fps float64
currentPtsTime time.Duration
currentPcrTime time.Duration
frameInterval time.Duration
continuity map[int]byte
isGenerating bool
}
@ -76,7 +79,7 @@ func NewTsGenerator(fps float64) (g *tsGenerator) {
return &tsGenerator{
outputChan: make(chan []byte, 1),
nalInputChan: make(chan []byte, 1),
fps: fps,
frameInterval: time.Duration(float64(time.Second) / fps),
currentPtsTime: ptsOffset,
continuity: map[int]byte{
patPid: 0,
@ -164,15 +167,15 @@ func (g *tsGenerator) generate() {
// pts retuns the next presentation timestamp.
func (g *tsGenerator) pts() uint64 {
pts := uint64(g.currentPtsTime * 90000) // FIXME(kortschak): Name this magic number.
g.currentPtsTime += 1 / g.fps
pts := uint64(g.currentPtsTime.Seconds() * ptsFreq)
g.currentPtsTime += g.frameInterval
return pts
}
// pcr returns the next program clock reference.
func (g *tsGenerator) pcr() uint64 {
pcr := uint64(g.currentPcrTime * 90000) // FIXME(kortschak): Name this magic number.
g.currentPcrTime += 1 / g.fps
pcr := uint64(g.currentPcrTime.Seconds() * ptsFreq)
g.currentPcrTime += g.frameInterval
return pcr
}