Skip to content

Commit

Permalink
Fix exec handler run pipe instead of rtsp
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 3, 2024
1 parent 8a7ab63 commit fb1e761
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down

0 comments on commit fb1e761

Please sign in to comment.