mirror of
https://github.com/bluenviron/mediamtx
synced 2025-03-30 15:18:01 +00:00
add parameter disablePublisherOverride to disable publisher override (#230)
This commit is contained in:
parent
37c24f9edd
commit
0048a01584
@ -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"`
|
||||
|
@ -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)
|
||||
|
@ -448,45 +448,91 @@ func TestClientRTSPAutomaticProtocol(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientRTSPPublisherOverride(t *testing.T) {
|
||||
p, ok := testProgram("rtmpDisable: yes\n")
|
||||
require.Equal(t, true, ok)
|
||||
defer p.close()
|
||||
t.Run("enabled", func(t *testing.T) {
|
||||
p, ok := testProgram("rtmpDisable: 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",
|
||||
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()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
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())
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer source1.close()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
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()
|
||||
|
||||
source2, err := newContainer("ffmpeg", "source2", []string{
|
||||
"-re",
|
||||
"-stream_loop", "-1",
|
||||
"-i", "emptyvideo.mkv",
|
||||
"-c", "copy",
|
||||
"-f", "rtsp",
|
||||
"rtsp://" + ownDockerIP + ":8554/teststream",
|
||||
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())
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer source2.close()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
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) {
|
||||
|
@ -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…
Reference in New Issue
Block a user