最近发现如果客户端退出,在一分钟左右的时间内仍然能够获取原来ServerMediaSession的Client数量。
在源代码中加入log,RTSPClientConnection在客户端退出时,及时地断开并销毁。
而ServerMediaSession的数量在RTSPClientSession销毁的时候才减为0。
在BasicTaskScheduler0::scheduleDelayedTask中,对加入DelayQueue中的AlarmHandler调试发现,当客户端退出,存在一个Delay值为65s的Entry。
然后通过全局搜索65,发现在创建RTSPServer时,有一个参数变量reclamationSeconds,默认值为65。
其注释如下:
// If "reclamationSeconds" > 0, then the "RTSPClientSession" state for
// each client will get reclaimed (and the corresponding RTP stream(s)
// torn down) if no RTSP commands - or RTCP "RR" packets - from the
// client are received in at least "reclamationSeconds" seconds.
在创建RTSPServer时指定reclamationSeconds的值,将影响到RTSPClientSession的回收时间。