8
8
"net/url"
9
9
"os"
10
10
"os/exec"
11
+ "slices"
11
12
"strings"
12
13
"sync"
13
14
"time"
@@ -80,7 +81,7 @@ func execHandle(rawURL string) (core.Producer, error) {
80
81
return handleRTSP (rawURL , cmd , path )
81
82
}
82
83
83
- func handlePipe (_ string , cmd * exec.Cmd , query url.Values ) (core.Producer , error ) {
84
+ func handlePipe (source string , cmd * exec.Cmd , query url.Values ) (core.Producer , error ) {
84
85
if query .Get ("backchannel" ) == "1" {
85
86
return stdin .NewClient (cmd )
86
87
}
@@ -104,12 +105,17 @@ func handlePipe(_ string, cmd *exec.Cmd, query url.Values) (core.Producer, error
104
105
return nil , fmt .Errorf ("exec/pipe: %w\n %s" , err , cmd .Stderr )
105
106
}
106
107
108
+ if info , ok := prod .(core.Info ); ok {
109
+ info .SetProtocol ("pipe" )
110
+ setRemoteInfo (info , source , cmd .Args )
111
+ }
112
+
107
113
log .Debug ().Stringer ("launch" , time .Since (ts )).Msg ("[exec] run pipe" )
108
114
109
115
return prod , nil
110
116
}
111
117
112
- func handleRTSP (url string , cmd * exec.Cmd , path string ) (core.Producer , error ) {
118
+ func handleRTSP (source string , cmd * exec.Cmd , path string ) (core.Producer , error ) {
113
119
if log .Trace ().Enabled () {
114
120
cmd .Stdout = os .Stdout
115
121
}
@@ -131,7 +137,7 @@ func handleRTSP(url string, cmd *exec.Cmd, path string) (core.Producer, error) {
131
137
ts := time .Now ()
132
138
133
139
if err := cmd .Start (); err != nil {
134
- log .Error ().Err (err ).Str ("url " , url ).Msg ("[exec]" )
140
+ log .Error ().Err (err ).Str ("source " , source ).Msg ("[exec]" )
135
141
return nil , err
136
142
}
137
143
@@ -143,13 +149,14 @@ func handleRTSP(url string, cmd *exec.Cmd, path string) (core.Producer, error) {
143
149
select {
144
150
case <- time .After (time .Second * 60 ):
145
151
_ = cmd .Process .Kill ()
146
- log .Error ().Str ("url " , url ).Msg ("[exec] timeout" )
152
+ log .Error ().Str ("source " , source ).Msg ("[exec] timeout" )
147
153
return nil , errors .New ("exec: timeout" )
148
154
case <- done :
149
155
// limit message size
150
156
return nil , fmt .Errorf ("exec/rtsp\n %s" , cmd .Stderr )
151
157
case prod := <- waiter :
152
158
log .Debug ().Stringer ("launch" , time .Since (ts )).Msg ("[exec] run rtsp" )
159
+ setRemoteInfo (prod , source , cmd .Args )
153
160
prod .OnClose = func () error {
154
161
log .Debug ().Msgf ("[exec] kill rtsp" )
155
162
return errors .Join (cmd .Process .Kill (), cmd .Wait ())
@@ -210,3 +217,15 @@ func trimSpace(b []byte) []byte {
210
217
}
211
218
return b [start :stop ]
212
219
}
220
+
221
+ func setRemoteInfo (info core.Info , source string , args []string ) {
222
+ info .SetSource (source )
223
+
224
+ if i := slices .Index (args , "-i" ); i > 0 && i < len (args )- 1 {
225
+ rawURL := args [i + 1 ]
226
+ if u , err := url .Parse (rawURL ); err == nil && u .Host != "" {
227
+ info .SetRemoteAddr (u .Host )
228
+ info .SetURL (rawURL )
229
+ }
230
+ }
231
+ }
0 commit comments