mirror of https://bitbucket.org/ausocean/av.git
Fixing timestamp problem
This commit is contained in:
parent
31eb35b5e8
commit
4d152494c5
|
@ -30,7 +30,7 @@ import (
|
|||
"bitbucket.org/ausocean/av/flv"
|
||||
//"../flv"
|
||||
_ "fmt"
|
||||
_ "time"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -59,6 +59,8 @@ type flvGenerator struct {
|
|||
lastTagSize int
|
||||
currentTimestamp uint32
|
||||
header flv.Header
|
||||
startTime time.Time
|
||||
firstTag bool
|
||||
}
|
||||
|
||||
// GetInputChan returns the input channel to the generator. This is where the
|
||||
|
@ -83,6 +85,7 @@ func NewFlvGenerator(audio bool, video bool, fps uint) (g *flvGenerator) {
|
|||
g.lastTagSize = 0
|
||||
g.inputChan = make(chan []byte, inputChanLength)
|
||||
g.outputChan = make(chan []byte, outputChanLength)
|
||||
g.firstTag = true
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -105,8 +108,12 @@ func (g *flvGenerator) GenHeader() {
|
|||
// getNextTimestamp generates and returns the next timestamp based on the given
|
||||
// fps rate
|
||||
func (g *flvGenerator) getNextTimestamp() (timestamp uint32) {
|
||||
if g.firstTag {
|
||||
g.startTime = time.Now()
|
||||
firstTage = false
|
||||
}
|
||||
timestamp = g.currentTimestamp
|
||||
g.currentTimestamp += uint32(1000) / uint32(g.fps)
|
||||
g.currentTimestamp += uint32(time.Now().sub(g.startTime).Seconds()*float64(1000))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -311,13 +311,15 @@ func (r *revidInst) outputClips() {
|
|||
now := time.Now()
|
||||
prevTime := now
|
||||
bytes := 0
|
||||
fps, _ := strconv.Atoi(r.config.FrameRate)
|
||||
delay := int64(float64(1000) / float64(fps))
|
||||
delay := 0
|
||||
for r.isRunning {
|
||||
// Here we slow things down as much as we can to decrease cpu usage
|
||||
switch {
|
||||
case r.ringBuffer.GetNoOfElements() < 2:
|
||||
delay++
|
||||
time.Sleep(time.Duration(delay) * time.Millisecond)
|
||||
case delay > 10:
|
||||
delay-=10
|
||||
}
|
||||
// If the ringbuffer has something we can read and send off
|
||||
if clip, err := r.ringBuffer.Read(); err == nil {
|
||||
|
|
Loading…
Reference in New Issue