fix: rtsp send conn read timeout

This commit is contained in:
langhuihui
2024-10-09 14:34:08 +08:00
parent 03383d9cfd
commit cb7b013897
2 changed files with 23 additions and 21 deletions
+3 -1
View File
@@ -72,8 +72,10 @@ func (r *AVRingReader) ReadFrame(conf *config.Subscribe) (err error) {
idr := r.Track.GetIDR()
if idr != nil {
startRing = idr
} else {
} else if r.Track.ICodecCtx != nil {
r.Warn("no IDRring", "track", r.Track.FourCC().String())
} else {
r.Warn("no codec")
}
switch conf.SubMode {
case SUBMODE_REAL:
+20 -20
View File
@@ -44,17 +44,18 @@ type NetConnection struct {
// internal
auth *util.Auth
conn net.Conn
keepalive int
sequence int
Session string
sdp string
uri string
writing atomic.Bool
state State
stateMu sync.Mutex
SDP string
auth *util.Auth
conn net.Conn
keepalive int
sequence int
Session string
sdp string
uri string
writing atomic.Bool
state State
stateMu sync.Mutex
SDP string
keepaliveTS time.Time
}
func (c *NetConnection) StartWrite() {
@@ -264,7 +265,7 @@ func (c *NetConnection) Receive(sendMode bool) (channelID byte, buf []byte, err
var size int
if magic[0] != '$' {
magicWord := string(magic)
c.Warn("not magic", "magic", magicWord)
//c.Warn("not magic", "magic", magicWord)
switch magicWord {
case "RTSP":
var res *util.Response
@@ -363,14 +364,13 @@ func (c *NetConnection) Receive(sendMode bool) (channelID byte, buf []byte, err
}
}
//if keepaliveDT != 0 && ts.After(keepaliveTS) {
// req := &tcp.Request{Method: MethodOptions, URL: c.URL}
// if err = c.WriteRequest(req); err != nil {
// return
// }
//
// keepaliveTS = ts.Add(keepaliveDT)
//}
if ts.After(c.keepaliveTS) {
req := &util.Request{Method: MethodOptions, URL: c.URL}
if err = c.WriteRequest(req); err != nil {
return
}
c.keepaliveTS = ts.Add(25 * time.Second)
}
return
}