在gop_cache中简单的对环形队列缓存进行封装

pull/8/head
liquanqing 5 years ago committed by yoko
parent 3d8c1c3d58
commit 2347363a18

@ -99,20 +99,32 @@ func (gc *GOPCache) Feed(msg rtmp.AVMsg, lg LazyGet) {
if gc.gopSize > 1 {
if msg.IsVideoKeyNalu() {
gc.gopRing[gc.gopRingLast].Clear()
gc.gopRing[gc.gopRingLast].Feed(msg, lg())
gc.gopRingLast = (gc.gopRingLast + 1) % gc.gopSize
if gc.gopRingLast == gc.gopRingFirst {
gc.gopRingFirst = (gc.gopRingFirst + 1) % gc.gopSize
}
gc.feedNewGop(msg, lg())
} else {
if gc.gopRingLast != gc.gopRingFirst {
gc.gopRing[(gc.gopRingLast - 1 + gc.gopSize) % gc.gopSize].Feed(msg, lg())
}
gc.feedLastGop(msg, lg())
}
}
}
func (gc *GOPCache) feedLastGop(msg rtmp.AVMsg, b []byte) {
if gc.gopRingLast != gc.gopRingFirst {
gc.gopRing[(gc.gopRingLast - 1 + gc.gopSize) % gc.gopSize].Feed(msg, b)
}
}
func (gc *GOPCache) feedNewGop(msg rtmp.AVMsg, b []byte) {
gc.gopRing[gc.gopRingLast].Clear()
gc.gopRing[gc.gopRingLast].Feed(msg, b)
gc.gopRingLast = (gc.gopRingLast + 1) % gc.gopSize
if gc.gopRingLast == gc.gopRingFirst {
gc.gopRingFirst = (gc.gopRingFirst + 1) % gc.gopSize
}
}
func (gc *GOPCache) isGopEmpty() bool {
return gc.gopRingFirst == gc.gopRingLast
}
func (gc *GOPCache) GetGopLen() int{
return (gc.gopRingLast + gc.gopSize - gc.gopRingFirst) % gc.gopSize
}
@ -124,13 +136,6 @@ func (gc *GOPCache) GetGopDataAt(pos int) [][]byte {
return gc.gopRing[(pos + gc.gopRingFirst) % gc.gopSize].data
}
func (gc *GOPCache) LastGOP() *GOP {
if gc.GetGopLen() == 0 {
return nil
}
return &gc.gopRing[(gc.gopRingLast - 1 + gc.gopSize) % gc.gopSize]
}
func (gc *GOPCache) Clear() {
gc.Metadata = nil
gc.VideoSeqHeader = nil

Loading…
Cancel
Save