From ba692413771b0ca020e5bf08f4d9244c6e59db37 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Tue, 13 Feb 2024 23:36:40 +0100 Subject: [PATCH] hls: stop spamming 'stream doesn't contain any supported codec' when hlsAlwaysRemux is true (#3018) --- internal/servers/hls/muxer.go | 2 +- internal/servers/hls/muxer_instance.go | 7 +++++-- internal/servers/rtmp/conn.go | 6 ++++-- internal/servers/webrtc/session.go | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/servers/hls/muxer.go b/internal/servers/hls/muxer.go index a840bfc5..92506407 100644 --- a/internal/servers/hls/muxer.go +++ b/internal/servers/hls/muxer.go @@ -153,7 +153,7 @@ func (m *muxer) runInner() error { } err = mi.initialize() if err != nil { - if m.remoteAddr != "" { + if m.remoteAddr != "" || errors.Is(err, errNoSupportedCodecs) { return err } diff --git a/internal/servers/hls/muxer_instance.go b/internal/servers/hls/muxer_instance.go index cd122c72..8b1a408d 100644 --- a/internal/servers/hls/muxer_instance.go +++ b/internal/servers/hls/muxer_instance.go @@ -1,6 +1,7 @@ package hls import ( + "errors" "fmt" "os" "path/filepath" @@ -18,6 +19,9 @@ import ( "github.com/gin-gonic/gin" ) +var errNoSupportedCodecs = errors.New( + "the stream doesn't contain any supported codec, which are currently H265, H264, Opus, MPEG-4 Audio") + type muxerInstance struct { variant conf.HLSVariant segmentCount int @@ -43,8 +47,7 @@ func (mi *muxerInstance) initialize() error { if videoTrack == nil && audioTrack == nil { mi.stream.RemoveReader(mi.writer) - return fmt.Errorf( - "the stream doesn't contain any supported codec, which are currently H265, H264, Opus, MPEG-4 Audio") + return errNoSupportedCodecs } var muxerDirectory string diff --git a/internal/servers/rtmp/conn.go b/internal/servers/rtmp/conn.go index 4d145c86..0af7e4bc 100644 --- a/internal/servers/rtmp/conn.go +++ b/internal/servers/rtmp/conn.go @@ -32,6 +32,9 @@ const ( pauseAfterAuthError = 2 * time.Second ) +var errNoSupportedCodecs = errors.New( + "the stream doesn't contain any supported codec, which are currently H264, MPEG-4 Audio, MPEG-1/2 Audio") + func pathNameAndQuery(inURL *url.URL) (string, url.Values, string) { // remove leading and trailing slashes inserted by OBS and some other clients tmp := strings.TrimRight(inURL.String(), "/") @@ -212,8 +215,7 @@ func (c *conn) runRead(conn *rtmp.Conn, u *url.URL) error { writer) if videoFormat == nil && audioFormat == nil { - return fmt.Errorf( - "the stream doesn't contain any supported codec, which are currently H264, MPEG-4 Audio, MPEG-1/2 Audio") + return errNoSupportedCodecs } c.Log(logger.Info, "is reading from path '%s', %s", diff --git a/internal/servers/webrtc/session.go b/internal/servers/webrtc/session.go index db922c99..620d4c3f 100644 --- a/internal/servers/webrtc/session.go +++ b/internal/servers/webrtc/session.go @@ -32,6 +32,9 @@ import ( "github.com/bluenviron/mediamtx/internal/unit" ) +var errNoSupportedCodecs = errors.New( + "the stream doesn't contain any supported codec, which are currently AV1, VP9, VP8, H264, Opus, G722, G711") + type setupStreamFunc func(*webrtc.OutgoingTrack) error func findVideoTrack( @@ -547,8 +550,7 @@ func (s *session) runRead() (int, error) { audioTrack, audioSetup := findAudioTrack(stream, writer) if videoTrack == nil && audioTrack == nil { - return http.StatusBadRequest, fmt.Errorf( - "the stream doesn't contain any supported codec, which are currently AV1, VP9, VP8, H264, Opus, G722, G711") + return http.StatusBadRequest, errNoSupportedCodecs } tracks, err := pc.SetupOutgoingTracks(videoTrack, audioTrack)