Skip to content

Commit d9cfc58

Browse files
author
Datanoise
committed
fix: disable ICY metadata for Ogg streams to prevent demuxer corruption and CRC errors
1 parent 83bca34 commit d9cfc58

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

relay/relay.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ func (r *Relay) GetStream(mount string) (*Stream, bool) {
244244
return s, ok
245245
}
246246

247+
// IsOgg returns true if the stream is Ogg-based (Ogg/Vorbis, Ogg/Opus, etc)
248+
func (s *Stream) IsOgg() bool {
249+
ct := strings.ToLower(s.ContentType)
250+
return strings.Contains(ct, "ogg") || strings.Contains(ct, "opus")
251+
}
252+
247253
// Close closes all listeners on the stream
248254
func (s *Stream) Close() {
249255
s.mu.Lock()

server/server.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,6 @@ func (s *Server) handleListener(w http.ResponseWriter, r *http.Request) {
846846
w.Header().Set("X-Accel-Buffering", "no")
847847
}
848848

849-
// ICY Metadata negotiation
850-
metaint := 0
851-
if r.Header.Get("Icy-MetaData") == "1" {
852-
metaint = 16000 // Standard interval
853-
w.Header().Set("icy-metaint", "16000")
854-
w.Header().Set("icy-name", s.Config.PageTitle)
855-
}
856-
857849
flusher, _ := w.(http.Flusher)
858850
id := r.RemoteAddr + "-" + fmt.Sprintf("%d", time.Now().UnixNano())
859851
logrus.WithFields(logrus.Fields{"mount": mount, "ip": r.RemoteAddr, "ua": r.Header.Get("User-Agent")}).Info("Listener connected")
@@ -889,6 +881,16 @@ func (s *Server) handleListener(w http.ResponseWriter, r *http.Request) {
889881
return
890882
}
891883

884+
// ICY Metadata negotiation
885+
metaint := 0
886+
// Ogg/Opus handles its own metadata. Injecting ICY metadata into an Ogg
887+
// stream corrupts the framing and causes CRC errors.
888+
if r.Header.Get("Icy-MetaData") == "1" && !stream.IsOgg() {
889+
metaint = 16000 // Standard interval
890+
w.Header().Set("icy-metaint", "16000")
891+
w.Header().Set("icy-name", s.Config.PageTitle)
892+
}
893+
892894
if s.Config.MaxListeners > 0 && stream.ListenersCount() >= s.Config.MaxListeners {
893895
http.Error(w, "Server Full", http.StatusServiceUnavailable)
894896
return

0 commit comments

Comments
 (0)