2023-07-31 19:20:09 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
"github.com/bluenviron/gortsplib/v4/pkg/description"
|
2023-10-31 13:19:04 +00:00
|
|
|
mcmpegts "github.com/bluenviron/mediacommon/pkg/formats/mpegts"
|
2023-07-31 19:20:09 +00:00
|
|
|
"github.com/datarhei/gosrt"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
2023-08-30 09:24:14 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/asyncwriter"
|
2023-07-31 19:20:09 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/conf"
|
2023-10-31 13:19:04 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/defs"
|
2023-08-05 15:18:04 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/externalcmd"
|
2023-11-26 21:06:07 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/hooks"
|
2023-07-31 19:20:09 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
2023-10-31 13:19:04 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/protocols/mpegts"
|
2023-07-31 19:20:09 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/stream"
|
|
|
|
)
|
|
|
|
|
2023-09-23 10:55:45 +00:00
|
|
|
func srtCheckPassphrase(connReq srt.ConnRequest, passphrase string) error {
|
|
|
|
if passphrase == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !connReq.IsEncrypted() {
|
|
|
|
return fmt.Errorf("connection is encrypted, but not passphrase is defined in configuration")
|
|
|
|
}
|
|
|
|
|
|
|
|
err := connReq.SetPassphrase(passphrase)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid passphrase")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
type srtConnState int
|
|
|
|
|
|
|
|
const (
|
|
|
|
srtConnStateRead srtConnState = iota + 1
|
|
|
|
srtConnStatePublish
|
|
|
|
)
|
|
|
|
|
|
|
|
type srtConnPathManager interface {
|
|
|
|
addReader(req pathAddReaderReq) pathAddReaderRes
|
|
|
|
addPublisher(req pathAddPublisherReq) pathAddPublisherRes
|
|
|
|
}
|
|
|
|
|
|
|
|
type srtConnParent interface {
|
|
|
|
logger.Writer
|
|
|
|
closeConn(*srtConn)
|
|
|
|
}
|
|
|
|
|
|
|
|
type srtConn struct {
|
2023-11-26 21:06:07 +00:00
|
|
|
rtspAddress string
|
|
|
|
readTimeout conf.StringDuration
|
|
|
|
writeTimeout conf.StringDuration
|
|
|
|
writeQueueSize int
|
|
|
|
udpMaxPayloadSize int
|
|
|
|
connReq srt.ConnRequest
|
|
|
|
runOnConnect string
|
|
|
|
runOnConnectRestart bool
|
|
|
|
runOnDisconnect string
|
|
|
|
wg *sync.WaitGroup
|
|
|
|
externalCmdPool *externalcmd.Pool
|
|
|
|
pathManager srtConnPathManager
|
|
|
|
parent srtConnParent
|
2023-07-31 19:20:09 +00:00
|
|
|
|
|
|
|
ctx context.Context
|
|
|
|
ctxCancel func()
|
|
|
|
created time.Time
|
|
|
|
uuid uuid.UUID
|
|
|
|
mutex sync.RWMutex
|
|
|
|
state srtConnState
|
|
|
|
pathName string
|
2023-09-16 17:21:48 +00:00
|
|
|
sconn srt.Conn
|
2023-07-31 19:20:09 +00:00
|
|
|
|
|
|
|
chNew chan srtNewConnReq
|
|
|
|
chSetConn chan srt.Conn
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSRTConn(
|
|
|
|
parentCtx context.Context,
|
2023-09-16 17:21:48 +00:00
|
|
|
rtspAddress string,
|
2023-07-31 19:20:09 +00:00
|
|
|
readTimeout conf.StringDuration,
|
|
|
|
writeTimeout conf.StringDuration,
|
2023-08-26 11:25:21 +00:00
|
|
|
writeQueueSize int,
|
2023-07-31 19:20:09 +00:00
|
|
|
udpMaxPayloadSize int,
|
|
|
|
connReq srt.ConnRequest,
|
2023-09-16 17:21:48 +00:00
|
|
|
runOnConnect string,
|
|
|
|
runOnConnectRestart bool,
|
|
|
|
runOnDisconnect string,
|
2023-07-31 19:20:09 +00:00
|
|
|
wg *sync.WaitGroup,
|
2023-08-05 15:18:04 +00:00
|
|
|
externalCmdPool *externalcmd.Pool,
|
2023-07-31 19:20:09 +00:00
|
|
|
pathManager srtConnPathManager,
|
|
|
|
parent srtConnParent,
|
|
|
|
) *srtConn {
|
|
|
|
ctx, ctxCancel := context.WithCancel(parentCtx)
|
|
|
|
|
|
|
|
c := &srtConn{
|
2023-11-26 21:06:07 +00:00
|
|
|
rtspAddress: rtspAddress,
|
|
|
|
readTimeout: readTimeout,
|
|
|
|
writeTimeout: writeTimeout,
|
|
|
|
writeQueueSize: writeQueueSize,
|
|
|
|
udpMaxPayloadSize: udpMaxPayloadSize,
|
|
|
|
connReq: connReq,
|
|
|
|
runOnConnect: runOnConnect,
|
|
|
|
runOnConnectRestart: runOnConnectRestart,
|
|
|
|
runOnDisconnect: runOnDisconnect,
|
|
|
|
wg: wg,
|
|
|
|
externalCmdPool: externalCmdPool,
|
|
|
|
pathManager: pathManager,
|
|
|
|
parent: parent,
|
|
|
|
ctx: ctx,
|
|
|
|
ctxCancel: ctxCancel,
|
|
|
|
created: time.Now(),
|
|
|
|
uuid: uuid.New(),
|
|
|
|
chNew: make(chan srtNewConnReq),
|
|
|
|
chSetConn: make(chan srt.Conn),
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Log(logger.Info, "opened")
|
|
|
|
|
|
|
|
c.wg.Add(1)
|
|
|
|
go c.run()
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *srtConn) close() {
|
|
|
|
c.ctxCancel()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *srtConn) Log(level logger.Level, format string, args ...interface{}) {
|
|
|
|
c.parent.Log(level, "[conn %v] "+format, append([]interface{}{c.connReq.RemoteAddr()}, args...)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *srtConn) ip() net.IP {
|
|
|
|
return c.connReq.RemoteAddr().(*net.UDPAddr).IP
|
|
|
|
}
|
|
|
|
|
2023-09-16 17:21:48 +00:00
|
|
|
func (c *srtConn) run() { //nolint:dupl
|
2023-07-31 19:20:09 +00:00
|
|
|
defer c.wg.Done()
|
|
|
|
|
2023-11-26 21:06:07 +00:00
|
|
|
onDisconnectHook := hooks.OnConnect(hooks.OnConnectParams{
|
|
|
|
Logger: c,
|
|
|
|
ExternalCmdPool: c.externalCmdPool,
|
|
|
|
RunOnConnect: c.runOnConnect,
|
|
|
|
RunOnConnectRestart: c.runOnConnectRestart,
|
|
|
|
RunOnDisconnect: c.runOnDisconnect,
|
|
|
|
RTSPAddress: c.rtspAddress,
|
|
|
|
Desc: c.apiReaderDescribe(),
|
|
|
|
})
|
|
|
|
defer onDisconnectHook()
|
2023-09-16 17:21:48 +00:00
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
err := c.runInner()
|
|
|
|
|
|
|
|
c.ctxCancel()
|
|
|
|
|
|
|
|
c.parent.closeConn(c)
|
|
|
|
|
2023-09-09 21:37:56 +00:00
|
|
|
c.Log(logger.Info, "closed: %v", err)
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *srtConn) runInner() error {
|
|
|
|
var req srtNewConnReq
|
|
|
|
select {
|
|
|
|
case req = <-c.chNew:
|
|
|
|
case <-c.ctx.Done():
|
|
|
|
return errors.New("terminated")
|
|
|
|
}
|
|
|
|
|
|
|
|
answerSent, err := c.runInner2(req)
|
|
|
|
|
|
|
|
if !answerSent {
|
|
|
|
req.res <- nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *srtConn) runInner2(req srtNewConnReq) (bool, error) {
|
|
|
|
parts := strings.Split(req.connReq.StreamId(), ":")
|
2023-11-16 22:32:17 +00:00
|
|
|
if (len(parts) < 2 || len(parts) > 5) || (parts[0] != "read" && parts[0] != "publish") {
|
2023-07-31 19:20:09 +00:00
|
|
|
return false, fmt.Errorf("invalid streamid '%s':"+
|
2023-11-16 22:32:17 +00:00
|
|
|
" it must be 'action:pathname[:query]' or 'action:pathname:user:pass[:query]', "+
|
|
|
|
"where action is either read or publish, pathname is the path name, user and pass are the credentials, "+
|
|
|
|
"query is an optional token containing additional information",
|
2023-07-31 19:20:09 +00:00
|
|
|
req.connReq.StreamId())
|
|
|
|
}
|
|
|
|
|
|
|
|
pathName := parts[1]
|
|
|
|
user := ""
|
|
|
|
pass := ""
|
2023-11-16 22:32:17 +00:00
|
|
|
query := ""
|
2023-07-31 19:20:09 +00:00
|
|
|
|
2023-11-16 22:32:17 +00:00
|
|
|
if len(parts) == 4 || len(parts) == 5 {
|
2023-07-31 19:20:09 +00:00
|
|
|
user, pass = parts[2], parts[3]
|
|
|
|
}
|
|
|
|
|
2023-11-16 22:32:17 +00:00
|
|
|
if len(parts) == 3 {
|
|
|
|
query = parts[2]
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(parts) == 5 {
|
|
|
|
query = parts[4]
|
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
if parts[0] == "publish" {
|
2023-11-16 22:32:17 +00:00
|
|
|
return c.runPublish(req, pathName, user, pass, query)
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
2023-11-16 22:32:17 +00:00
|
|
|
return c.runRead(req, pathName, user, pass, query)
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
|
2023-11-16 22:32:17 +00:00
|
|
|
func (c *srtConn) runPublish(req srtNewConnReq, pathName string, user string, pass string, query string) (bool, error) {
|
2023-07-31 19:20:09 +00:00
|
|
|
res := c.pathManager.addPublisher(pathAddPublisherReq{
|
2023-10-18 09:50:26 +00:00
|
|
|
author: c,
|
|
|
|
accessRequest: pathAccessRequest{
|
|
|
|
name: pathName,
|
|
|
|
ip: c.ip(),
|
|
|
|
publish: true,
|
|
|
|
user: user,
|
|
|
|
pass: pass,
|
|
|
|
proto: authProtocolSRT,
|
|
|
|
id: &c.uuid,
|
2023-11-16 22:32:17 +00:00
|
|
|
query: query,
|
2023-07-31 19:20:09 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if res.err != nil {
|
|
|
|
if terr, ok := res.err.(*errAuthentication); ok {
|
|
|
|
// TODO: re-enable. Currently this freezes the listener.
|
|
|
|
// wait some seconds to stop brute force attacks
|
|
|
|
// <-time.After(srtPauseAfterAuthError)
|
|
|
|
return false, terr
|
|
|
|
}
|
|
|
|
return false, res.err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer res.path.removePublisher(pathRemovePublisherReq{author: c})
|
|
|
|
|
2023-09-23 10:55:45 +00:00
|
|
|
err := srtCheckPassphrase(req.connReq, res.path.conf.SRTPublishPassphrase)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
sconn, err := c.exchangeRequestWithConn(req)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
|
|
|
c.mutex.Lock()
|
|
|
|
c.state = srtConnStatePublish
|
|
|
|
c.pathName = pathName
|
2023-09-16 17:21:48 +00:00
|
|
|
c.sconn = sconn
|
2023-07-31 19:20:09 +00:00
|
|
|
c.mutex.Unlock()
|
|
|
|
|
|
|
|
readerErr := make(chan error)
|
|
|
|
go func() {
|
|
|
|
readerErr <- c.runPublishReader(sconn, res.path)
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case err := <-readerErr:
|
|
|
|
sconn.Close()
|
|
|
|
return true, err
|
|
|
|
|
|
|
|
case <-c.ctx.Done():
|
|
|
|
sconn.Close()
|
|
|
|
<-readerErr
|
|
|
|
return true, errors.New("terminated")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *srtConn) runPublishReader(sconn srt.Conn, path *path) error {
|
|
|
|
sconn.SetReadDeadline(time.Now().Add(time.Duration(c.readTimeout)))
|
2023-10-31 13:19:04 +00:00
|
|
|
r, err := mcmpegts.NewReader(mcmpegts.NewBufferedReader(sconn))
|
2023-07-31 19:20:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-30 09:24:14 +00:00
|
|
|
decodeErrLogger := logger.NewLimitedLogger(c)
|
2023-08-26 21:34:39 +00:00
|
|
|
|
|
|
|
r.OnDecodeError(func(err error) {
|
|
|
|
decodeErrLogger.Log(logger.Warn, err.Error())
|
|
|
|
})
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
var stream *stream.Stream
|
|
|
|
|
2023-10-31 13:19:04 +00:00
|
|
|
medias, err := mpegts.ToStream(r, &stream)
|
2023-09-19 20:33:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-08-05 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
rres := path.startPublisher(pathStartPublisherReq{
|
|
|
|
author: c,
|
2023-08-26 16:54:28 +00:00
|
|
|
desc: &description.Session{Medias: medias},
|
2023-07-31 19:20:09 +00:00
|
|
|
generateRTPPackets: true,
|
|
|
|
})
|
|
|
|
if rres.err != nil {
|
|
|
|
return rres.err
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = rres.stream
|
|
|
|
|
|
|
|
for {
|
|
|
|
err := r.Read()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-16 22:32:17 +00:00
|
|
|
func (c *srtConn) runRead(req srtNewConnReq, pathName string, user string, pass string, query string) (bool, error) {
|
2023-07-31 19:20:09 +00:00
|
|
|
res := c.pathManager.addReader(pathAddReaderReq{
|
2023-10-18 09:50:26 +00:00
|
|
|
author: c,
|
|
|
|
accessRequest: pathAccessRequest{
|
|
|
|
name: pathName,
|
2023-07-31 19:20:09 +00:00
|
|
|
ip: c.ip(),
|
|
|
|
user: user,
|
|
|
|
pass: pass,
|
|
|
|
proto: authProtocolSRT,
|
|
|
|
id: &c.uuid,
|
2023-11-16 22:32:17 +00:00
|
|
|
query: query,
|
2023-07-31 19:20:09 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if res.err != nil {
|
|
|
|
if terr, ok := res.err.(*errAuthentication); ok {
|
|
|
|
// TODO: re-enable. Currently this freezes the listener.
|
|
|
|
// wait some seconds to stop brute force attacks
|
|
|
|
// <-time.After(srtPauseAfterAuthError)
|
|
|
|
return false, terr
|
|
|
|
}
|
|
|
|
return false, res.err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer res.path.removeReader(pathRemoveReaderReq{author: c})
|
|
|
|
|
2023-09-23 10:55:45 +00:00
|
|
|
err := srtCheckPassphrase(req.connReq, res.path.conf.SRTReadPassphrase)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
sconn, err := c.exchangeRequestWithConn(req)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
defer sconn.Close()
|
|
|
|
|
|
|
|
c.mutex.Lock()
|
|
|
|
c.state = srtConnStateRead
|
|
|
|
c.pathName = pathName
|
2023-09-16 17:21:48 +00:00
|
|
|
c.sconn = sconn
|
2023-07-31 19:20:09 +00:00
|
|
|
c.mutex.Unlock()
|
|
|
|
|
2023-08-30 09:24:14 +00:00
|
|
|
writer := asyncwriter.New(c.writeQueueSize, c)
|
2023-07-31 19:20:09 +00:00
|
|
|
|
2023-08-31 21:01:47 +00:00
|
|
|
defer res.stream.RemoveReader(writer)
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
bw := bufio.NewWriterSize(sconn, srtMaxPayloadSize(c.udpMaxPayloadSize))
|
|
|
|
|
2023-10-14 20:52:10 +00:00
|
|
|
err = mpegtsSetupWrite(res.stream, writer, bw, sconn, time.Duration(c.writeTimeout))
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Log(logger.Info, "is reading from path '%s', %s",
|
2023-10-14 20:52:10 +00:00
|
|
|
res.path.name, readerMediaInfo(writer, res.stream))
|
2023-07-31 19:20:09 +00:00
|
|
|
|
2023-11-26 21:06:07 +00:00
|
|
|
onUnreadHook := hooks.OnRead(hooks.OnReadParams{
|
|
|
|
Logger: c,
|
|
|
|
ExternalCmdPool: c.externalCmdPool,
|
|
|
|
Conf: res.path.safeConf(),
|
|
|
|
ExternalCmdEnv: res.path.externalCmdEnv(),
|
|
|
|
Reader: c.apiReaderDescribe(),
|
|
|
|
Query: query,
|
|
|
|
})
|
2023-10-18 09:50:26 +00:00
|
|
|
defer onUnreadHook()
|
2023-09-16 17:21:48 +00:00
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
// disable read deadline
|
|
|
|
sconn.SetReadDeadline(time.Time{})
|
|
|
|
|
2023-08-30 09:24:14 +00:00
|
|
|
writer.Start()
|
2023-07-31 19:20:09 +00:00
|
|
|
|
2023-08-26 17:45:10 +00:00
|
|
|
select {
|
|
|
|
case <-c.ctx.Done():
|
2023-08-30 09:24:14 +00:00
|
|
|
writer.Stop()
|
2023-08-26 17:45:10 +00:00
|
|
|
return true, fmt.Errorf("terminated")
|
|
|
|
|
2023-08-30 09:24:14 +00:00
|
|
|
case err := <-writer.Error():
|
2023-08-26 17:45:10 +00:00
|
|
|
return true, err
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *srtConn) exchangeRequestWithConn(req srtNewConnReq) (srt.Conn, error) {
|
|
|
|
req.res <- c
|
|
|
|
|
|
|
|
select {
|
|
|
|
case sconn := <-c.chSetConn:
|
|
|
|
return sconn, nil
|
|
|
|
|
|
|
|
case <-c.ctx.Done():
|
|
|
|
return nil, errors.New("terminated")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// new is called by srtListener through srtServer.
|
|
|
|
func (c *srtConn) new(req srtNewConnReq) *srtConn {
|
|
|
|
select {
|
|
|
|
case c.chNew <- req:
|
|
|
|
return <-req.res
|
|
|
|
|
|
|
|
case <-c.ctx.Done():
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// setConn is called by srtListener .
|
|
|
|
func (c *srtConn) setConn(sconn srt.Conn) {
|
|
|
|
select {
|
|
|
|
case c.chSetConn <- sconn:
|
|
|
|
case <-c.ctx.Done():
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// apiReaderDescribe implements reader.
|
2023-10-31 13:19:04 +00:00
|
|
|
func (c *srtConn) apiReaderDescribe() defs.APIPathSourceOrReader {
|
|
|
|
return defs.APIPathSourceOrReader{
|
2023-07-31 19:20:09 +00:00
|
|
|
Type: "srtConn",
|
|
|
|
ID: c.uuid.String(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 13:19:04 +00:00
|
|
|
// APISourceDescribe implements source.
|
|
|
|
func (c *srtConn) APISourceDescribe() defs.APIPathSourceOrReader {
|
2023-07-31 19:20:09 +00:00
|
|
|
return c.apiReaderDescribe()
|
|
|
|
}
|
|
|
|
|
2023-10-31 13:19:04 +00:00
|
|
|
func (c *srtConn) apiItem() *defs.APISRTConn {
|
2023-07-31 19:20:09 +00:00
|
|
|
c.mutex.RLock()
|
|
|
|
defer c.mutex.RUnlock()
|
|
|
|
|
|
|
|
bytesReceived := uint64(0)
|
|
|
|
bytesSent := uint64(0)
|
|
|
|
|
2023-09-28 15:45:34 +00:00
|
|
|
if c.sconn != nil {
|
2023-07-31 19:20:09 +00:00
|
|
|
var s srt.Statistics
|
2023-09-16 17:21:48 +00:00
|
|
|
c.sconn.Stats(&s)
|
2023-07-31 19:20:09 +00:00
|
|
|
bytesReceived = s.Accumulated.ByteRecv
|
|
|
|
bytesSent = s.Accumulated.ByteSent
|
|
|
|
}
|
|
|
|
|
2023-10-31 13:19:04 +00:00
|
|
|
return &defs.APISRTConn{
|
2023-07-31 19:20:09 +00:00
|
|
|
ID: c.uuid,
|
|
|
|
Created: c.created,
|
|
|
|
RemoteAddr: c.connReq.RemoteAddr().String(),
|
2023-10-31 13:19:04 +00:00
|
|
|
State: func() defs.APISRTConnState {
|
2023-07-31 19:20:09 +00:00
|
|
|
switch c.state {
|
|
|
|
case srtConnStateRead:
|
2023-10-31 13:19:04 +00:00
|
|
|
return defs.APISRTConnStateRead
|
2023-07-31 19:20:09 +00:00
|
|
|
|
|
|
|
case srtConnStatePublish:
|
2023-10-31 13:19:04 +00:00
|
|
|
return defs.APISRTConnStatePublish
|
2023-07-31 19:20:09 +00:00
|
|
|
|
|
|
|
default:
|
2023-10-31 13:19:04 +00:00
|
|
|
return defs.APISRTConnStateIdle
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
}(),
|
|
|
|
Path: c.pathName,
|
|
|
|
BytesReceived: bytesReceived,
|
|
|
|
BytesSent: bytesSent,
|
|
|
|
}
|
|
|
|
}
|