add isDurationNormal to pktqueue
This commit is contained in:
parent
32022b73d4
commit
d1e2d3d2ff
@ -11,22 +11,33 @@ type timePacket struct {
|
||||
|
||||
type stream struct {
|
||||
pkts []timePacket
|
||||
lastDuration float64
|
||||
lastNormalDuration float64
|
||||
isVideo bool
|
||||
}
|
||||
|
||||
func (self *stream) isDurationNormal(v float64) bool {
|
||||
return v > float64(0.0) && v < float64(1.0)
|
||||
}
|
||||
|
||||
func (self *stream) Read(flush bool) (ok bool, pkt timePacket) {
|
||||
if len(self.pkts) > 1 {
|
||||
ok = true
|
||||
pkt := self.pkts[0]
|
||||
pkt = self.pkts[0]
|
||||
pkt.Duration = self.pkts[1].time - self.pkts[0].time
|
||||
self.lastDuration = pkt.Duration
|
||||
self.pkts = self.pkts[1:]
|
||||
} else if len(self.pkts) == 1 && flush {
|
||||
ok = true
|
||||
pkt := self.pkts[0]
|
||||
pkt.Duration = self.lastDuration
|
||||
pkt = self.pkts[0]
|
||||
pkt.Duration = self.lastNormalDuration
|
||||
self.pkts = self.pkts[1:]
|
||||
}
|
||||
if ok {
|
||||
if !self.isDurationNormal(pkt.Duration) {
|
||||
pkt.Duration = self.lastNormalDuration
|
||||
} else {
|
||||
self.lastNormalDuration = pkt.Duration
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -41,12 +52,20 @@ func (self *Queue) CurrentTime() float64 {
|
||||
return self.time
|
||||
}
|
||||
|
||||
func (self *Queue) Alloc(n int) {
|
||||
self.streams = make([]*stream, n)
|
||||
func (self *Queue) Alloc(streams []av.CodecData) {
|
||||
self.streams = make([]*stream, len(streams))
|
||||
for i := 0; i < len(self.streams); i++ {
|
||||
self.streams[i] = &stream{
|
||||
isVideo: streams[i].IsVideo(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Queue) Clear() {
|
||||
self.Alloc(len(self.streams))
|
||||
for _, stream := range self.streams {
|
||||
stream.pkts = []timePacket{}
|
||||
stream.lastNormalDuration = float64(0.0)
|
||||
}
|
||||
self.time = 0.0
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user