mirror of https://bitbucket.org/ausocean/av.git
generator: clean up time
This commit is contained in:
parent
15d2fc6afe
commit
1fb325314d
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue