mirror of
https://github.com/bluenviron/mediamtx
synced 2025-03-03 10:57:30 +00:00
api: add "created" field to RTSP sessions, RTMP connections, HLS muxers
This commit is contained in:
parent
055e08ac6c
commit
092a2be3a8
@ -295,6 +295,8 @@ components:
|
||||
RTSPSession:
|
||||
type: object
|
||||
properties:
|
||||
created:
|
||||
type: string
|
||||
remoteAddr:
|
||||
type: string
|
||||
state:
|
||||
@ -313,6 +315,8 @@ components:
|
||||
RTMPConn:
|
||||
type: object
|
||||
properties:
|
||||
created:
|
||||
type: string
|
||||
remoteAddr:
|
||||
type: string
|
||||
state:
|
||||
@ -322,6 +326,8 @@ components:
|
||||
HLSMuxer:
|
||||
type: object
|
||||
properties:
|
||||
created:
|
||||
type: string
|
||||
lastRequest:
|
||||
type: string
|
||||
|
||||
|
@ -127,6 +127,7 @@ type hlsMuxer struct {
|
||||
|
||||
ctx context.Context
|
||||
ctxCancel func()
|
||||
created time.Time
|
||||
path *path
|
||||
ringBuffer *ringbuffer.RingBuffer
|
||||
lastRequestTime *int64
|
||||
@ -173,6 +174,7 @@ func newHLSMuxer(
|
||||
parent: parent,
|
||||
ctx: ctx,
|
||||
ctxCancel: ctxCancel,
|
||||
created: time.Now(),
|
||||
lastRequestTime: func() *int64 {
|
||||
v := time.Now().Unix()
|
||||
return &v
|
||||
@ -240,6 +242,7 @@ func (m *hlsMuxer) run() {
|
||||
|
||||
case req := <-m.chAPIHLSMuxersList:
|
||||
req.data.Items[m.name] = hlsServerAPIMuxersListItem{
|
||||
Created: m.created,
|
||||
LastRequest: time.Unix(atomic.LoadInt64(m.lastRequestTime), 0).String(),
|
||||
}
|
||||
close(req.res)
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
gopath "path"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@ -27,7 +28,8 @@ func (nilWriter) Write(p []byte) (int, error) {
|
||||
}
|
||||
|
||||
type hlsServerAPIMuxersListItem struct {
|
||||
LastRequest string `json:"lastRequest"`
|
||||
Created time.Time `json:"created"`
|
||||
LastRequest string `json:"lastRequest"`
|
||||
}
|
||||
|
||||
type hlsServerAPIMuxersListData struct {
|
||||
|
@ -67,7 +67,7 @@ type pathParent interface {
|
||||
}
|
||||
|
||||
type pathRTSPSession interface {
|
||||
IsRTSPSession()
|
||||
isRTSPSession()
|
||||
}
|
||||
|
||||
type pathReaderState int
|
||||
|
@ -74,6 +74,7 @@ type rtmpConn struct {
|
||||
|
||||
ctx context.Context
|
||||
ctxCancel func()
|
||||
created time.Time
|
||||
path *path
|
||||
ringBuffer *ringbuffer.RingBuffer // read
|
||||
state rtmpConnState
|
||||
@ -115,6 +116,7 @@ func newRTMPConn(
|
||||
parent: parent,
|
||||
ctx: ctx,
|
||||
ctxCancel: ctxCancel,
|
||||
created: time.Now(),
|
||||
}
|
||||
|
||||
c.log(logger.Info, "opened")
|
||||
@ -125,18 +127,11 @@ func newRTMPConn(
|
||||
return c
|
||||
}
|
||||
|
||||
// Close closes a Conn.
|
||||
func (c *rtmpConn) close() {
|
||||
c.ctxCancel()
|
||||
}
|
||||
|
||||
// ID returns the ID of the Conn.
|
||||
func (c *rtmpConn) ID() string {
|
||||
return c.id
|
||||
}
|
||||
|
||||
// RemoteAddr returns the remote address of the Conn.
|
||||
func (c *rtmpConn) RemoteAddr() net.Addr {
|
||||
func (c *rtmpConn) remoteAddr() net.Addr {
|
||||
return c.nconn.RemoteAddr()
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aler9/rtsp-simple-server/internal/conf"
|
||||
"github.com/aler9/rtsp-simple-server/internal/externalcmd"
|
||||
@ -14,8 +15,9 @@ import (
|
||||
)
|
||||
|
||||
type rtmpServerAPIConnsListItem struct {
|
||||
RemoteAddr string `json:"remoteAddr"`
|
||||
State string `json:"state"`
|
||||
Created time.Time `json:"created"`
|
||||
RemoteAddr string `json:"remoteAddr"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type rtmpServerAPIConnsListData struct {
|
||||
@ -202,8 +204,9 @@ outer:
|
||||
}
|
||||
|
||||
for c := range s.conns {
|
||||
data.Items[c.ID()] = rtmpServerAPIConnsListItem{
|
||||
RemoteAddr: c.RemoteAddr().String(),
|
||||
data.Items[c.id] = rtmpServerAPIConnsListItem{
|
||||
Created: c.created,
|
||||
RemoteAddr: c.remoteAddr().String(),
|
||||
State: func() string {
|
||||
switch c.safeState() {
|
||||
case rtmpConnStateRead:
|
||||
@ -222,7 +225,7 @@ outer:
|
||||
case req := <-s.chAPIConnsKick:
|
||||
res := func() bool {
|
||||
for c := range s.conns {
|
||||
if c.ID() == req.id {
|
||||
if c.id == req.id {
|
||||
delete(s.conns, c)
|
||||
c.close()
|
||||
return true
|
||||
@ -266,7 +269,7 @@ func (s *rtmpServer) newConnID() (string, error) {
|
||||
|
||||
alreadyPresent := func() bool {
|
||||
for c := range s.conns {
|
||||
if c.ID() == id {
|
||||
if c.id == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,9 @@ import (
|
||||
)
|
||||
|
||||
type rtspServerAPISessionsListItem struct {
|
||||
RemoteAddr string `json:"remoteAddr"`
|
||||
State string `json:"state"`
|
||||
Created time.Time `json:"created"`
|
||||
RemoteAddr string `json:"remoteAddr"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type rtspServerAPISessionsListData struct {
|
||||
@ -242,7 +243,7 @@ func (s *rtspServer) newSessionID() (string, error) {
|
||||
|
||||
alreadyPresent := func() bool {
|
||||
for _, s := range s.sessions {
|
||||
if s.ID() == id {
|
||||
if s.id == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -408,8 +409,9 @@ func (s *rtspServer) apiSessionsList(req rtspServerAPISessionsListReq) rtspServe
|
||||
}
|
||||
|
||||
for _, s := range s.sessions {
|
||||
data.Items[s.ID()] = rtspServerAPISessionsListItem{
|
||||
RemoteAddr: s.RemoteAddr().String(),
|
||||
data.Items[s.id] = rtspServerAPISessionsListItem{
|
||||
Created: s.created,
|
||||
RemoteAddr: s.remoteAddr().String(),
|
||||
State: func() string {
|
||||
switch s.safeState() {
|
||||
case gortsplib.ServerSessionStatePrePlay,
|
||||
@ -440,7 +442,7 @@ func (s *rtspServer) apiSessionsKick(req rtspServerAPISessionsKickReq) rtspServe
|
||||
defer s.mutex.RUnlock()
|
||||
|
||||
for key, se := range s.sessions {
|
||||
if se.ID() == req.id {
|
||||
if se.id == req.id {
|
||||
se.close()
|
||||
delete(s.sessions, key)
|
||||
se.onClose(liberrors.ErrServerTerminated{})
|
||||
|
@ -38,6 +38,7 @@ type rtspSession struct {
|
||||
pathManager rtspSessionPathManager
|
||||
parent rtspSessionParent
|
||||
|
||||
created time.Time
|
||||
path *path
|
||||
state gortsplib.ServerSessionState
|
||||
stateMutex sync.Mutex
|
||||
@ -65,6 +66,7 @@ func newRTSPSession(
|
||||
externalCmdPool: externalCmdPool,
|
||||
pathManager: pathManager,
|
||||
parent: parent,
|
||||
created: time.Now(),
|
||||
}
|
||||
|
||||
s.log(logger.Info, "created by %v", s.author.NetConn().RemoteAddr())
|
||||
@ -77,13 +79,8 @@ func (s *rtspSession) close() {
|
||||
s.ss.Close()
|
||||
}
|
||||
|
||||
// IsRTSPSession implements pathRTSPSession.
|
||||
func (s *rtspSession) IsRTSPSession() {}
|
||||
|
||||
// ID returns the public ID of the session.
|
||||
func (s *rtspSession) ID() string {
|
||||
return s.id
|
||||
}
|
||||
// isRTSPSession implements pathRTSPSession.
|
||||
func (s *rtspSession) isRTSPSession() {}
|
||||
|
||||
func (s *rtspSession) safeState() gortsplib.ServerSessionState {
|
||||
s.stateMutex.Lock()
|
||||
@ -91,8 +88,7 @@ func (s *rtspSession) safeState() gortsplib.ServerSessionState {
|
||||
return s.state
|
||||
}
|
||||
|
||||
// RemoteAddr returns the remote address of the author of the session.
|
||||
func (s *rtspSession) RemoteAddr() net.Addr {
|
||||
func (s *rtspSession) remoteAddr() net.Addr {
|
||||
return s.author.NetConn().RemoteAddr()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user