Skip to content

Commit

Permalink
Merge pull request #78 from ZSC714725/gop_cache
Browse files Browse the repository at this point in the history
Gop cache
  • Loading branch information
ZSC714725 authored Apr 21, 2024
2 parents 5ece156 + 787e41a commit 81cb24d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions hook/gop_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (c *GopCache) feedLastGop(msg base.RtmpMsg) {
if c.isGopRingEmpty() {
return
}

idx := (c.last - 1 + c.gopSize) % c.gopSize
if c.singleGopMaxFrameNum == 0 || c.data[idx].size() <= c.singleGopMaxFrameNum {
c.data[idx].feed(msg)
Expand Down
8 changes: 6 additions & 2 deletions hook/hooksession.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type HookSession struct {
consumers sync.Map
hlssvr *hls.HlsServer
gopCache *GopCache
hasVideo bool
}

type consumerInfo struct {
Expand Down Expand Up @@ -93,7 +94,6 @@ func (session *HookSession) OnMsg(msg base.RtmpMsg) {
session.hlssvr.OnMsg(session.streamName, msg)
}

// TODO:做缓存处理/纯音频
session.consumers.Range(func(key, value interface{}) bool {
c := value.(*consumerInfo)

Expand Down Expand Up @@ -129,13 +129,17 @@ func (session *HookSession) OnMsg(msg base.RtmpMsg) {

c.subscriber.OnMsg(msg)
} else if msg.Header.MsgTypeId == base.RtmpTypeIdAudio {
if c.hasSendVideo {
if !session.hasVideo || c.hasSendVideo {
c.subscriber.OnMsg(msg)
}
}
return true
})

if !session.hasVideo && msg.IsVideoKeyNalu() {
session.hasVideo = true
}

session.gopCache.Feed(msg)
}

Expand Down

0 comments on commit 81cb24d

Please sign in to comment.