From fb1e7613cbd9aecef4ad2ec7a31cc4bbb9345088 Mon Sep 17 00:00:00 2001 From: Alex X Date: Fri, 3 May 2024 14:04:33 +0300 Subject: [PATCH] Fix exec handler run pipe instead of rtsp --- internal/exec/exec.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/exec/exec.go b/internal/exec/exec.go index e3ffe5a2..36a76473 100644 --- a/internal/exec/exec.go +++ b/internal/exec/exec.go @@ -49,34 +49,34 @@ func Init() { func execHandle(rawURL string) (core.Producer, error) { var path string + var query url.Values - rawURL, rawQuery, _ := strings.Cut(rawURL, "#") - - args := shell.QuoteSplit(rawURL[5:]) // remove `exec:` - for i, arg := range args { - if arg == "{output}" { - if rtsp.Port == "" { - return nil, errors.New("rtsp module disabled") - } - - sum := md5.Sum([]byte(rawURL)) - path = "/" + hex.EncodeToString(sum[:]) - args[i] = "rtsp://127.0.0.1:" + rtsp.Port + path - break + // RTSP flow should have `{output}` inside URL + // pipe flow may have `#{params}` inside URL + if i := strings.Index(rawURL, "{output}"); i > 0 { + if rtsp.Port == "" { + return nil, errors.New("exec: rtsp module disabled") } + + sum := md5.Sum([]byte(rawURL)) + path = "/" + hex.EncodeToString(sum[:]) + rawURL = rawURL[:i] + "rtsp://127.0.0.1:" + rtsp.Port + path + rawURL[i+8:] + } else if i = strings.IndexByte(rawURL, '#'); i > 0 { + query = streams.ParseQuery(rawURL[i+1:]) + rawURL = rawURL[:i] } + args := shell.QuoteSplit(rawURL[5:]) // remove `exec:` cmd := exec.Command(args[0], args[1:]...) if log.Debug().Enabled() { cmd.Stderr = os.Stderr } if path == "" { - query := streams.ParseQuery(rawQuery) return handlePipe(rawURL, cmd, query) } - return handleRTSP(rawURL, path, cmd) + return handleRTSP(rawURL, cmd, path) } func handlePipe(_ string, cmd *exec.Cmd, query url.Values) (core.Producer, error) { @@ -101,7 +101,7 @@ func handlePipe(_ string, cmd *exec.Cmd, query url.Values) (core.Producer, error return prod, err } -func handleRTSP(url, path string, cmd *exec.Cmd) (core.Producer, error) { +func handleRTSP(url string, cmd *exec.Cmd, path string) (core.Producer, error) { if log.Trace().Enabled() { cmd.Stdout = os.Stdout }