Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ components:
type: integer
format: uint64

# Custom
custom:
type: string

# Hooks
runOnInit:
type: string
Expand Down
3 changes: 3 additions & 0 deletions docs/4-other/17-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ paths:
# The following environment variables are available:
# * MTX_PATH: path name
# * RTSP_PORT: RTSP server port
# * MTX_CUSTOM: value of the path config field "Custom"
# * G1, G2, ...: regular expression groups, if path name is
# a regular expression.
runOnInit: ffmpeg -i my_file.mp4 -c copy -f rtsp rtsp://localhost:8554/mypath
Expand All @@ -59,6 +60,7 @@ pathDefaults:
# The following environment variables are available:
# * MTX_PATH: path name
# * MTX_QUERY: query parameters (passed by first reader)
# * MTX_CUSTOM: value of the path config field "Custom"
# * RTSP_PORT: RTSP server port
# * G1, G2, ...: regular expression groups, if path name is
# a regular expression.
Expand Down Expand Up @@ -90,6 +92,7 @@ pathDefaults:
# The following environment variables are available:
# * MTX_PATH: path name
# * MTX_QUERY: query parameters (passed by publisher)
# * MTX_CUSTOM: value of the path config field "Custom"
# * MTX_SOURCE_TYPE: source type
# * MTX_SOURCE_ID: source ID
# * RTSP_PORT: RTSP server port
Expand Down
3 changes: 3 additions & 0 deletions internal/conf/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ type Path struct {
RPICameraSecondaryFPS float64 `json:"-"` // filled by Validate()
RPICameraSecondaryMJPEGQuality uint `json:"-"` // filled by Validate()

// Custom
Custom string `json:"custom"` // custom value available as MTX_CUSTOM env var to RunOnInit, RunOn(Un)Demand, RunOn(Not)Ready

// Hooks
RunOnInit string `json:"runOnInit"`
RunOnInitRestart bool `json:"runOnInitRestart"`
Expand Down
1 change: 1 addition & 0 deletions internal/hooks/on_demand.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func OnDemand(params OnDemandParams) func(string) {
if params.Conf.RunOnDemand != "" || params.Conf.RunOnUnDemand != "" {
env = params.ExternalCmdEnv
env["MTX_QUERY"] = params.Query
env["MTX_CUSTOM"] = params.Conf.Custom
}

if params.Conf.RunOnDemand != "" {
Expand Down
6 changes: 5 additions & 1 deletion internal/hooks/on_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ type OnInitParams struct {
// OnInit is the OnInit hook.
func OnInit(params OnInitParams) func() {
var onInitCmd *externalcmd.Cmd
var env externalcmd.Environment

if params.Conf.RunOnInit != "" {
params.Logger.Log(logger.Info, "runOnInit command started")
env = params.ExternalCmdEnv
env["MTX_CUSTOM"] = params.Conf.Custom

onInitCmd = externalcmd.NewCmd(
params.ExternalCmdPool,
params.Conf.RunOnInit,
params.Conf.RunOnInitRestart,
params.ExternalCmdEnv,
env,
func(err error) {
params.Logger.Log(logger.Info, "runOnInit command exited: %v", err)
})
Expand Down
1 change: 1 addition & 0 deletions internal/hooks/on_ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func OnReady(params OnReadyParams) func() {
env["MTX_SOURCE_TYPE"] = params.Desc.Type
env["MTX_SOURCE_ID"] = params.Desc.ID
}
env["MTX_CUSTOM"] = params.Conf.Custom
}

if params.Conf.RunOnReady != "" {
Expand Down