Skip to content

Commit

Permalink
srt: support runOnRead (#2152)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Aug 5, 2023
1 parent dd91aba commit b198cc5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.WriteTimeout,
p.conf.ReadBufferCount,
p.conf.UDPMaxPayloadSize,
p.externalCmdPool,
p.pathManager,
p,
)
Expand Down
22 changes: 22 additions & 0 deletions internal/core/srt_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/google/uuid"

"github.com/bluenviron/mediamtx/internal/conf"
"github.com/bluenviron/mediamtx/internal/externalcmd"
"github.com/bluenviron/mediamtx/internal/formatprocessor"
"github.com/bluenviron/mediamtx/internal/logger"
"github.com/bluenviron/mediamtx/internal/stream"
Expand Down Expand Up @@ -64,6 +65,7 @@ type srtConn struct {
udpMaxPayloadSize int
connReq srt.ConnRequest
wg *sync.WaitGroup
externalCmdPool *externalcmd.Pool
pathManager srtConnPathManager
parent srtConnParent

Expand All @@ -88,6 +90,7 @@ func newSRTConn(
udpMaxPayloadSize int,
connReq srt.ConnRequest,
wg *sync.WaitGroup,
externalCmdPool *externalcmd.Pool,
pathManager srtConnPathManager,
parent srtConnParent,
) *srtConn {
Expand All @@ -100,6 +103,7 @@ func newSRTConn(
udpMaxPayloadSize: udpMaxPayloadSize,
connReq: connReq,
wg: wg,
externalCmdPool: externalCmdPool,
pathManager: pathManager,
parent: parent,
ctx: ctx,
Expand Down Expand Up @@ -746,6 +750,24 @@ func (c *srtConn) runRead(req srtNewConnReq, pathName string, user string, pass
c.Log(logger.Info, "is reading from path '%s', %s",
res.path.name, sourceMediaInfo(medias))

pathConf := res.path.safeConf()

if pathConf.RunOnRead != "" {
c.Log(logger.Info, "runOnRead command started")
onReadCmd := externalcmd.NewCmd(
c.externalCmdPool,
pathConf.RunOnRead,
pathConf.RunOnReadRestart,
res.path.externalCmdEnv(),
func(err error) {
c.Log(logger.Info, "runOnRead command exited: %v", err)
})
defer func() {
onReadCmd.Close()
c.Log(logger.Info, "runOnRead command stopped")
}()
}

w = mpegts.NewWriter(bw, tracks)

// disable read deadline
Expand Down
5 changes: 5 additions & 0 deletions internal/core/srt_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/google/uuid"

"github.com/bluenviron/mediamtx/internal/conf"
"github.com/bluenviron/mediamtx/internal/externalcmd"
"github.com/bluenviron/mediamtx/internal/logger"
)

Expand Down Expand Up @@ -60,6 +61,7 @@ type srtServer struct {
writeTimeout conf.StringDuration
readBufferCount int
udpMaxPayloadSize int
externalCmdPool *externalcmd.Pool
pathManager *pathManager
parent srtServerParent

Expand All @@ -84,6 +86,7 @@ func newSRTServer(
writeTimeout conf.StringDuration,
readBufferCount int,
udpMaxPayloadSize int,
externalCmdPool *externalcmd.Pool,
pathManager *pathManager,
parent srtServerParent,
) (*srtServer, error) {
Expand All @@ -103,6 +106,7 @@ func newSRTServer(
writeTimeout: writeTimeout,
readBufferCount: readBufferCount,
udpMaxPayloadSize: udpMaxPayloadSize,
externalCmdPool: externalCmdPool,
pathManager: pathManager,
parent: parent,
ctx: ctx,
Expand Down Expand Up @@ -161,6 +165,7 @@ outer:
s.udpMaxPayloadSize,
req.connReq,
&s.wg,
s.externalCmdPool,
s.pathManager,
s)
s.conns[c] = struct{}{}
Expand Down

0 comments on commit b198cc5

Please sign in to comment.