Browse Source

add parameter disablePublisherOverride to disable publisher override (#230)

pull/340/head
aler9 5 years ago
parent
commit
0048a01584
  1. 1
      internal/conf/path.go
  2. 5
      internal/path/path.go
  3. 46
      main_clientrtsp_test.go
  4. 8
      rtsp-simple-server.yml

1
internal/conf/path.go

@ -74,6 +74,7 @@ type PathConf struct { @@ -74,6 +74,7 @@ type PathConf struct {
SourceOnDemandStartTimeout time.Duration `yaml:"sourceOnDemandStartTimeout"`
SourceOnDemandCloseAfter time.Duration `yaml:"sourceOnDemandCloseAfter"`
SourceRedirect string `yaml:"sourceRedirect"`
DisablePublisherOverride bool `yaml:"disablePublisherOverride"`
Fallback string `yaml:"fallback"`
RunOnInit string `yaml:"runOnInit"`
RunOnInitRestart bool `yaml:"runOnInitRestart"`

5
internal/path/path.go

@ -689,6 +689,11 @@ func (pa *Path) onClientAnnounce(req client.AnnounceReq) { @@ -689,6 +689,11 @@ func (pa *Path) onClientAnnounce(req client.AnnounceReq) {
}
if pa.source != nil {
if pa.conf.DisablePublisherOverride {
req.Res <- client.AnnounceRes{nil, fmt.Errorf("another client is already publishing on path '%s'", pa.name)} //nolint:govet
return
}
pa.Log(logger.Info, "disconnecting existing publisher")
curPublisher := pa.source.(client.Client)
pa.removeClient(curPublisher)

46
main_clientrtsp_test.go

@ -448,6 +448,7 @@ func TestClientRTSPAutomaticProtocol(t *testing.T) { @@ -448,6 +448,7 @@ func TestClientRTSPAutomaticProtocol(t *testing.T) {
}
func TestClientRTSPPublisherOverride(t *testing.T) {
t.Run("enabled", func(t *testing.T) {
p, ok := testProgram("rtmpDisable: yes\n")
require.Equal(t, true, ok)
defer p.close()
@ -487,6 +488,51 @@ func TestClientRTSPPublisherOverride(t *testing.T) { @@ -487,6 +488,51 @@ func TestClientRTSPPublisherOverride(t *testing.T) {
require.NoError(t, err)
defer dest.close()
require.Equal(t, 0, dest.wait())
})
t.Run("disabled", func(t *testing.T) {
p, ok := testProgram("rtmpDisable: yes\n" +
"paths:\n" +
" all:\n" +
" disablePublisherOverride: yes\n")
require.Equal(t, true, ok)
defer p.close()
source1, err := newContainer("ffmpeg", "source1", []string{
"-re",
"-stream_loop", "-1",
"-i", "emptyvideo.mkv",
"-c", "copy",
"-f", "rtsp",
"rtsp://" + ownDockerIP + ":8554/teststream",
})
require.NoError(t, err)
defer source1.close()
time.Sleep(1 * time.Second)
source2, err := newContainer("ffmpeg", "source2", []string{
"-re",
"-stream_loop", "-1",
"-i", "emptyvideo.mkv",
"-c", "copy",
"-f", "rtsp",
"rtsp://" + ownDockerIP + ":8554/teststream",
})
require.NoError(t, err)
defer source2.close()
require.NotEqual(t, 0, source2.wait())
dest, err := newContainer("ffmpeg", "dest", []string{
"-i", "rtsp://" + ownDockerIP + ":8554/teststream",
"-vframes", "1",
"-f", "image2",
"-y", "/dev/null",
})
require.NoError(t, err)
defer dest.close()
require.Equal(t, 0, dest.wait())
})
}
func TestClientRTSPNonCompliantFrameSize(t *testing.T) {

8
rtsp-simple-server.yml

@ -114,8 +114,12 @@ paths: @@ -114,8 +114,12 @@ paths:
# redirected to.
sourceRedirect:
# fallback stream to redirect clients to when nobody is publishing to this path.
# this can be a relative path (i.e. /otherstream) or an absolute RTSP URL.
# if the source is "record" and a client is publishing, do not allow another
# client to disconnect the former and publish in its place.
disablePublisherOverride: no
# if the source is "record" and no one is publishing, redirect readers to this
# path. It can be can be a relative path (i.e. /otherstream) or an absolute RTSP URL.
fallback:
# username required to publish.

Loading…
Cancel
Save