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