From fc26b1ebc70b84e99c6b81e8f281a921c06e8ded Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Wed, 16 Nov 2022 21:15:18 +0800 Subject: [PATCH] patch for #241 --- conf/lalserver.conf.json | 2 +- conf/lalserver.conf.json.tmpl | 6 +++--- pkg/base/t_version.go | 2 +- pkg/logic/config.go | 26 +++++++++++++------------- pkg/remux/gop_cache.go | 32 ++++++++++++++++---------------- pkg/remux/gop_cache_mpegts.go | 30 +++++++++++++++--------------- pkg/remux/gop_cache_test.go | 2 +- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/conf/lalserver.conf.json b/conf/lalserver.conf.json index 3153000..b31ecc8 100644 --- a/conf/lalserver.conf.json +++ b/conf/lalserver.conf.json @@ -1,6 +1,6 @@ { "# doc of config": "https://pengrl.com/lal/#/ConfigBrief", - "conf_version": "v0.4.0", + "conf_version": "v0.4.1", "rtmp": { "enable": true, "addr": ":1935", diff --git a/conf/lalserver.conf.json.tmpl b/conf/lalserver.conf.json.tmpl index a69b379..b31ecc8 100644 --- a/conf/lalserver.conf.json.tmpl +++ b/conf/lalserver.conf.json.tmpl @@ -1,6 +1,6 @@ { "# doc of config": "https://pengrl.com/lal/#/ConfigBrief", - "conf_version": "v0.4.0", + "conf_version": "v0.4.1", "rtmp": { "enable": true, "addr": ":1935", @@ -27,7 +27,7 @@ "enable_https": true, "url_pattern": "/", "gop_num": 0, - "single_gop_max_frame_num": 0, + "single_gop_max_frame_num": 0 }, "hls": { "enable": true, @@ -45,7 +45,7 @@ "enable_https": true, "url_pattern": "/", "gop_num": 0, - "single_gop_max_frame_num": 0, + "single_gop_max_frame_num": 0 }, "rtsp": { "enable": true, diff --git a/pkg/base/t_version.go b/pkg/base/t_version.go index 12c5ed7..8cce129 100644 --- a/pkg/base/t_version.go +++ b/pkg/base/t_version.go @@ -19,7 +19,7 @@ import "strings" const LalVersion = "v0.32.0" // ConfVersion lalserver的配置文件的版本号 -const ConfVersion = "v0.4.0" +const ConfVersion = "v0.4.1" // HttpApiVersion lalserver的HTTP-API功能的版本号 const HttpApiVersion = "v0.4.2" diff --git a/pkg/logic/config.go b/pkg/logic/config.go index f41a707..7ca8ddc 100644 --- a/pkg/logic/config.go +++ b/pkg/logic/config.go @@ -51,15 +51,15 @@ type Config struct { } type RtmpConfig struct { - Enable bool `json:"enable"` - Addr string `json:"addr"` - RtmpsEnable bool `json:"rtmps_enable"` - RtmpsAddr string `json:"rtmps_addr"` - RtmpsCertFile string `json:"rtmps_cert_file"` - RtmpsKeyFile string `json:"rtmps_key_file"` - GopNum int `json:"gop_num"` // TODO(chef): refactor 更名为gop_cache_num - SingleGopMaxFrameNum int `json:"single_gop_max_frame_num"` - MergeWriteSize int `json:"merge_write_size"` + Enable bool `json:"enable"` + Addr string `json:"addr"` + RtmpsEnable bool `json:"rtmps_enable"` + RtmpsAddr string `json:"rtmps_addr"` + RtmpsCertFile string `json:"rtmps_cert_file"` + RtmpsKeyFile string `json:"rtmps_key_file"` + GopNum int `json:"gop_num"` // TODO(chef): refactor 更名为gop_cache_num + SingleGopMaxFrameNum int `json:"single_gop_max_frame_num"` + MergeWriteSize int `json:"merge_write_size"` } type InSessionConfig struct { @@ -74,15 +74,15 @@ type DefaultHttpConfig struct { type HttpflvConfig struct { CommonHttpServerConfig - GopNum int `json:"gop_num"` - SingleGopMaxFrameNum int `json:"single_gop_max_frame_num"` + GopNum int `json:"gop_num"` + SingleGopMaxFrameNum int `json:"single_gop_max_frame_num"` } type HttptsConfig struct { CommonHttpServerConfig - GopNum int `json:"gop_num"` - SingleGopMaxFrameNum int `json:"single_gop_max_frame_num"` + GopNum int `json:"gop_num"` + SingleGopMaxFrameNum int `json:"single_gop_max_frame_num"` } type HlsConfig struct { diff --git a/pkg/remux/gop_cache.go b/pkg/remux/gop_cache.go index d71c6b4..fe5d3b9 100644 --- a/pkg/remux/gop_cache.go +++ b/pkg/remux/gop_cache.go @@ -59,10 +59,10 @@ type GopCache struct { VideoSeqHeader []byte AacSeqHeader []byte - gopRing []Gop - gopRingFirst int - gopRingLast int - gopSize int + gopRing []Gop + gopRingFirst int + gopRingLast int + gopSize int singleGopMaxFrameNum int } @@ -71,15 +71,15 @@ type GopCache struct { // @param gopNum: gop缓存大小。 // - 如果为0,则不缓存音频数据,也即GOP缓存功能不生效。 // - 如果>0,则缓存[0, gopNum]个GOP,最多缓存 gopNum 个GOP。注意,最后一个GOP可能是不完整的。 -func NewGopCache(t string, uniqueKey string, gopNum int,singleGopMaxFrameNum int) *GopCache { +func NewGopCache(t string, uniqueKey string, gopNum int, singleGopMaxFrameNum int) *GopCache { return &GopCache{ - t: t, - uniqueKey: uniqueKey, - gopSize: gopNum + 1, - gopRing: make([]Gop, gopNum+1, gopNum+1), - gopRingFirst: 0, - gopRingLast: 0, - singleGopMaxFrameNum:singleGopMaxFrameNum, + t: t, + uniqueKey: uniqueKey, + gopSize: gopNum + 1, + gopRing: make([]Gop, gopNum+1, gopNum+1), + gopRingFirst: 0, + gopRingLast: 0, + singleGopMaxFrameNum: singleGopMaxFrameNum, } } @@ -155,8 +155,8 @@ func (gc *GopCache) Clear() { // 注意,如果GopCache为空,则不缓存msg func (gc *GopCache) feedLastGop(msg base.RtmpMsg, b []byte) { if !gc.isGopRingEmpty() { - gopPos:=(gc.gopRingLast-1+gc.gopSize)%gc.gopSize - if gc.gopRing[gopPos].len()<=gc.singleGopMaxFrameNum ||gc.singleGopMaxFrameNum==0{ + gopPos := (gc.gopRingLast - 1 + gc.gopSize) % gc.gopSize + if gc.gopRing[gopPos].len() <= gc.singleGopMaxFrameNum || gc.singleGopMaxFrameNum == 0 { gc.gopRing[gopPos].Feed(msg, b) } } @@ -198,6 +198,6 @@ func (g *Gop) Feed(msg base.RtmpMsg, b []byte) { func (g *Gop) Clear() { g.data = g.data[:0] } -func (g *Gop) len()int { +func (g *Gop) len() int { return len(g.data) -} \ No newline at end of file +} diff --git a/pkg/remux/gop_cache_mpegts.go b/pkg/remux/gop_cache_mpegts.go index c69a4ed..73f898a 100644 --- a/pkg/remux/gop_cache_mpegts.go +++ b/pkg/remux/gop_cache_mpegts.go @@ -17,21 +17,21 @@ type GopCacheMpegts struct { uniqueKey string gopNum int - gopRing []GopMpegts - gopRingFirst int - gopRingLast int - gopSize int + gopRing []GopMpegts + gopRingFirst int + gopRingLast int + gopSize int singleGopMaxFrameNum int } -func NewGopCacheMpegts(uniqueKey string, gopNum int,singleGopMaxFrameNum int) *GopCacheMpegts { +func NewGopCacheMpegts(uniqueKey string, gopNum int, singleGopMaxFrameNum int) *GopCacheMpegts { return &GopCacheMpegts{ - uniqueKey: uniqueKey, - gopNum: gopNum, - gopSize: gopNum + 1, - gopRing: make([]GopMpegts, gopNum+1, gopNum+1), - gopRingFirst: 0, - gopRingLast: 0, + uniqueKey: uniqueKey, + gopNum: gopNum, + gopSize: gopNum + 1, + gopRing: make([]GopMpegts, gopNum+1, gopNum+1), + gopRingFirst: 0, + gopRingLast: 0, singleGopMaxFrameNum: singleGopMaxFrameNum, } } @@ -74,8 +74,8 @@ func (gc *GopCacheMpegts) Clear() { // 注意,如果GopCache为空,则不缓存msg func (gc *GopCacheMpegts) feedLastGop(b []byte) { if !gc.isGopRingEmpty() { - gopPos:=(gc.gopRingLast-1+gc.gopSize)%gc.gopSize - if gc.gopRing[gopPos].len()<=gc.singleGopMaxFrameNum ||gc.singleGopMaxFrameNum==0{ + gopPos := (gc.gopRingLast - 1 + gc.gopSize) % gc.gopSize + if gc.gopRing[gopPos].len() <= gc.singleGopMaxFrameNum || gc.singleGopMaxFrameNum == 0 { gc.gopRing[gopPos].Feed(b) } @@ -121,6 +121,6 @@ func (g *GopMpegts) Feed(b []byte) { func (g *GopMpegts) Clear() { g.data = g.data[:0] } -func (g *GopMpegts) len()int { +func (g *GopMpegts) len() int { return len(g.data) -} \ No newline at end of file +} diff --git a/pkg/remux/gop_cache_test.go b/pkg/remux/gop_cache_test.go index 503a66b..86d4d0f 100644 --- a/pkg/remux/gop_cache_test.go +++ b/pkg/remux/gop_cache_test.go @@ -59,7 +59,7 @@ func TestGopCache_Feed(t *testing.T) { i4f := func() []byte { return []byte{1, 4} } p4f := func() []byte { return []byte{0, 4} } - nc := NewGopCache("rtmp", "test", 3,0) + nc := NewGopCache("rtmp", "test", 3, 0) assert.Equal(t, 0, nc.GetGopCount()) assert.Equal(t, nil, nc.GetGopDataAt(0)) assert.Equal(t, nil, nc.GetGopDataAt(1))