revid: accept multiple RTMP outputs

This change modifies the revid config RTMPURL field to be a slice
instead of a single string. This allows use to have multiple RTMP
outputs.
This commit is contained in:
Saxon Nelson-Milton 2023-03-05 08:25:14 +10:30
parent 66daab5e7c
commit f8fe900207
5 changed files with 28 additions and 16 deletions

View File

@ -233,7 +233,7 @@ type Config struct {
PoolWriteTimeout uint // The pool buffer write timeout in seconds.
RecPeriod float64 // How many seconds to record at a time.
Rotation uint // Rotation defines the video rotation angle in degrees Raspivid input.
RTMPURL string // RTMPURL specifies the Rtmp output destination URL. This must be defined if RTMP is to be used as an output.
RTMPURL []string // RTMPURL specifies the Rtmp output destination URL. This must be defined if RTMP is to be used as an output.
RTPAddress string // RTPAddress defines the RTP output destination.
SampleRate uint // Samples a second (Hz).
Saturation int

View File

@ -166,7 +166,7 @@ func TestUpdate(t *testing.T) {
PoolCapacity: 100000,
PoolWriteTimeout: 50,
Rotation: 180,
RTMPURL: "rtmp://url",
RTMPURL: []string{"rtmp://url"},
RTPAddress: "ip:port",
Saturation: -10,
VBRBitrate: 300000,

View File

@ -584,7 +584,13 @@ var Variables = []struct {
{
Name: KeyRTMPURL,
Type: typeString,
Update: func(c *Config, v string) { c.RTMPURL = v },
Update: func(c *Config, v string) {
v = strings.ReplaceAll(v, " ", "")
split := strings.Split(v, ",")
for _, s := range split {
c.RTMPURL = append(c.RTMPURL, s)
}
},
},
{
Name: KeyRTPAddress,

View File

@ -178,6 +178,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
// to mtsSenders if the output requires MPEGTS encoding, or flvSenders if the
// output requires FLV encoding.
var w io.WriteCloser
rtmpUrlIdx := 0
for _, out := range r.cfg.Outputs {
switch out {
case config.OutputHTTP:
@ -215,11 +216,16 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
mtsSenders = append(mtsSenders, w)
case config.OutputRTMP:
r.cfg.Logger.Debug("using RTMP output")
if rtmpUrlIdx > len(r.cfg.RTMPURL)-1 {
r.cfg.Logger.Warning("rtmp outputs exceed available rtmp urls")
break
}
pb := pool.NewBuffer(int(r.cfg.PoolStartElementSize), int(nElements), writeTimeout)
w, err := newRtmpSender(r.cfg.RTMPURL, rtmpConnectionMaxTries, pb, r.cfg.Logger, r.bitrate.Report)
w, err := newRtmpSender(r.cfg.RTMPURL[rtmpUrlIdx], rtmpConnectionMaxTries, pb, r.cfg.Logger, r.bitrate.Report)
if err != nil {
r.cfg.Logger.Warning("rtmp connect error", "error", err.Error())
}
rtmpUrlIdx++
flvSenders = append(flvSenders, w)
}
}

View File

@ -203,7 +203,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
for testNum, test := range tests {
// Create a new config and reset revid with it.
const dummyURL = "rtmp://dummy"
c := config.Config{Logger: &testLogger{}, Outputs: test.outputs, RTMPURL: dummyURL}
c := config.Config{Logger: &testLogger{}, Outputs: test.outputs, RTMPURL: []string{dummyURL}}
err := rv.setConfig(c)
if err != nil {
t.Fatalf("unexpected error: %v for test %v", err, testNum)