Skip to content

Commit

Permalink
refactor mv RtmpServerSessionReadAvTimeoutMs LogicCheckSessionAliveIn…
Browse files Browse the repository at this point in the history
…tervalSec to base pkg
  • Loading branch information
q191201771 committed Jun 3, 2024
1 parent cb2cf03 commit d7b0aaf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
27 changes: 25 additions & 2 deletions pkg/base/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,28 @@ import "github.com/q191201771/naza/pkg/nazalog"

var Log = nazalog.GetGlobalLogger()

// AddCors2HlsFlag 是否为hls增加跨域相关的http header
var AddCors2HlsFlag = true
// ----- hls --------------------
var (
// AddCors2HlsFlag 是否为hls增加跨域相关的http header
AddCors2HlsFlag = true
)

// ----- rtmp --------------------
var (
// RtmpServerSessionReadAvTimeoutMs rtmp server pub session,读音视频数据超时
RtmpServerSessionReadAvTimeoutMs = 120000
)

// ----- logic --------------------
var (
// LogicCheckSessionAliveIntervalSec
//
// 检查session是否有数据传输的时间间隔,该间隔内没有数据传输的session将被关闭。
//
// 对于输入型session,检查一定时间内,是否没有收到数据。
//
// 对于输出型session,检查一定时间内,是否没有发送数据。
// 注意,socket阻塞无法发送和上层没有向该session喂入数据都算没有发送数据。
//
LogicCheckSessionAliveIntervalSec uint32 = 120
)
2 changes: 1 addition & 1 deletion pkg/logic/group__.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (group *Group) disposeInactiveSessions(tickCount uint32) {

// 以下都是以 CheckSessionAliveIntervalSec 为间隔的清理逻辑

if tickCount%CheckSessionAliveIntervalSec != 0 {
if tickCount%base.LogicCheckSessionAliveIntervalSec != 0 {
return
}

Expand Down
12 changes: 0 additions & 12 deletions pkg/logic/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ var (
// - rtsp pull: rtsp.PullSessionOption.PullTimeoutMs
// - httpflv pull: httpflv.PullSessionOption.PullTimeoutMs ReadTimeoutMs

// CheckSessionAliveIntervalSec
//
// 检查session是否有数据传输的时间间隔,该间隔内没有数据传输的session将被关闭。
//
// 对于输入型session,检查一定时间内,是否没有收到数据。
//
// 对于输出型session,检查一定时间内,是否没有发送数据。
// 注意,socket阻塞无法发送和上层没有向该session喂入数据都算没有发送数据。
//
//CheckSessionAliveIntervalSec uint32 = 10
CheckSessionAliveIntervalSec uint32 = 120

RelayPushTimeoutMs = 10000
RelayPushWriteAvTimeoutMs = 10000

Expand Down
2 changes: 1 addition & 1 deletion pkg/rtmp/server_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (s *ServerSession) modConnProps() {

switch s.sessionStat.BaseType() {
case base.SessionBaseTypePubStr:
s.conn.ModReadTimeoutMs(serverSessionReadAvTimeoutMs)
s.conn.ModReadTimeoutMs(base.RtmpServerSessionReadAvTimeoutMs)
case base.SessionBaseTypeSubStr:
s.conn.ModWriteTimeoutMs(serverSessionWriteAvTimeoutMs)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/rtmp/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ package rtmp

import "github.com/q191201771/naza/pkg/nazalog"

// TODO chef 一些更专业的配置项,暂时只在该源码文件中配置,不提供外部配置接口
// 一些更专业的配置项,暂时只在该源码文件中配置,不提供外部配置接口
// 一些配置移入了pkg/base/var.go中

var (
Log = nazalog.GetGlobalLogger()
Expand All @@ -20,9 +21,6 @@ var (
readBufSize = 4096 // server session connection读缓冲的大小
wChanSize = 1024 // server session 发送数据时,channel 的大小

//serverSessionReadAvTimeoutMs = 10000 // server pub session,读音视频数据超时
serverSessionReadAvTimeoutMs = 120000 // server pub session,读音视频数据超时

serverSessionWriteAvTimeoutMs = 10000 // server sub session,写音视频数据超时
//writeBufSize = 4096 // 注意,因为lal server在group中使用writev做merge合并发送,这个废弃不需要了

Expand Down

0 comments on commit d7b0aaf

Please sign in to comment.