diff --git a/pkg/remux/gop_cache.go b/pkg/remux/gop_cache.go index 1848ff2..ff13b2f 100644 --- a/pkg/remux/gop_cache.go +++ b/pkg/remux/gop_cache.go @@ -155,8 +155,9 @@ func (gc *GopCache) Clear() { // 注意,如果GopCache为空,则不缓存msg func (gc *GopCache) feedLastGop(msg base.RtmpMsg, b []byte) { if !gc.isGopRingEmpty() { - if gc.gopRing[(gc.gopRingLast-1+gc.gopSize)%gc.gopSize].len()<=gc.singleGopMaxNum ||gc.singleGopMaxNum==0{ - gc.gopRing[(gc.gopRingLast-1+gc.gopSize)%gc.gopSize].Feed(msg, b) + gopPos:=(gc.gopRingLast-1+gc.gopSize)%gc.gopSize + if gc.gopRing[gopPos].len()<=gc.singleGopMaxNum ||gc.singleGopMaxNum==0{ + gc.gopRing[gopPos].Feed(msg, b) } } } diff --git a/pkg/remux/gop_cache_mpegts.go b/pkg/remux/gop_cache_mpegts.go index 380bed3..2f7101f 100644 --- a/pkg/remux/gop_cache_mpegts.go +++ b/pkg/remux/gop_cache_mpegts.go @@ -74,8 +74,9 @@ func (gc *GopCacheMpegts) Clear() { // 注意,如果GopCache为空,则不缓存msg func (gc *GopCacheMpegts) feedLastGop(b []byte) { if !gc.isGopRingEmpty() { - if gc.gopRing[(gc.gopRingLast-1+gc.gopSize)%gc.gopSize].len()<=gc.singleGopMaxNum ||gc.singleGopMaxNum==0{ - gc.gopRing[(gc.gopRingLast-1+gc.gopSize)%gc.gopSize].Feed(b) + gopPos:=(gc.gopRingLast-1+gc.gopSize)%gc.gopSize + if gc.gopRing[gopPos].len()<=gc.singleGopMaxNum ||gc.singleGopMaxNum==0{ + gc.gopRing[gopPos].Feed(b) } }