Skip to content

Commit 96504e2

Browse files
committedJun 16, 2024
BIG rewrite stream info
1 parent ecfe802 commit 96504e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1042
-853
lines changed
 

‎internal/exec/exec.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"os/exec"
11+
"slices"
1112
"strings"
1213
"sync"
1314
"time"
@@ -80,7 +81,7 @@ func execHandle(rawURL string) (core.Producer, error) {
8081
return handleRTSP(rawURL, cmd, path)
8182
}
8283

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) {
8485
if query.Get("backchannel") == "1" {
8586
return stdin.NewClient(cmd)
8687
}
@@ -104,12 +105,17 @@ func handlePipe(_ string, cmd *exec.Cmd, query url.Values) (core.Producer, error
104105
return nil, fmt.Errorf("exec/pipe: %w\n%s", err, cmd.Stderr)
105106
}
106107

108+
if info, ok := prod.(core.Info); ok {
109+
info.SetProtocol("pipe")
110+
setRemoteInfo(info, source, cmd.Args)
111+
}
112+
107113
log.Debug().Stringer("launch", time.Since(ts)).Msg("[exec] run pipe")
108114

109115
return prod, nil
110116
}
111117

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) {
113119
if log.Trace().Enabled() {
114120
cmd.Stdout = os.Stdout
115121
}
@@ -131,7 +137,7 @@ func handleRTSP(url string, cmd *exec.Cmd, path string) (core.Producer, error) {
131137
ts := time.Now()
132138

133139
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]")
135141
return nil, err
136142
}
137143

@@ -143,13 +149,14 @@ func handleRTSP(url string, cmd *exec.Cmd, path string) (core.Producer, error) {
143149
select {
144150
case <-time.After(time.Second * 60):
145151
_ = cmd.Process.Kill()
146-
log.Error().Str("url", url).Msg("[exec] timeout")
152+
log.Error().Str("source", source).Msg("[exec] timeout")
147153
return nil, errors.New("exec: timeout")
148154
case <-done:
149155
// limit message size
150156
return nil, fmt.Errorf("exec/rtsp\n%s", cmd.Stderr)
151157
case prod := <-waiter:
152158
log.Debug().Stringer("launch", time.Since(ts)).Msg("[exec] run rtsp")
159+
setRemoteInfo(prod, source, cmd.Args)
153160
prod.OnClose = func() error {
154161
log.Debug().Msgf("[exec] kill rtsp")
155162
return errors.Join(cmd.Process.Kill(), cmd.Wait())
@@ -210,3 +217,15 @@ func trimSpace(b []byte) []byte {
210217
}
211218
return b[start:stop]
212219
}
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+
}

‎internal/ffmpeg/producer.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
type Producer struct {
16-
core.SuperProducer
16+
core.Connection
1717
url string
1818
query url.Values
1919
ffmpeg core.Producer
@@ -31,7 +31,8 @@ func NewProducer(url string) (core.Producer, error) {
3131
return nil, errors.New("ffmpeg: unsupported params: " + url[i:])
3232
}
3333

34-
p.Type = "FFmpeg producer"
34+
p.ID = core.NewID()
35+
p.FormatName = "ffmpeg"
3536
p.Medias = []*core.Media{
3637
{
3738
// we can support only audio, because don't know FmtpLine for H264 and PayloadType for MJPEG
@@ -81,7 +82,7 @@ func (p *Producer) Stop() error {
8182

8283
func (p *Producer) MarshalJSON() ([]byte, error) {
8384
if p.ffmpeg == nil {
84-
return json.Marshal(p.SuperProducer)
85+
return json.Marshal(p.Connection)
8586
}
8687
return json.Marshal(p.ffmpeg)
8788
}

0 commit comments

Comments
 (0)
Please sign in to comment.