Skip to content

Commit 296edc6

Browse files
author
Datanoise
committed
feat: professional AutoDJ upgrades, AJAX UI, and TCP-level security
1 parent 69c2e73 commit 296edc6

9 files changed

Lines changed: 542 additions & 345 deletions

File tree

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type AutoDJConfig struct {
5959
MPDEnabled bool `json:"mpd_enabled"`
6060
MPDPort string `json:"mpd_port"`
6161
MPDPassword string `json:"mpd_password"`
62+
Visible bool `json:"visible"`
6263
}
6364

6465
type Config struct {

relay/client.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package relay
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"io"
@@ -184,15 +185,46 @@ func (rm *RelayManager) performPull(ctx context.Context, inst *RelayInstance) {
184185
}
185186

186187
func (rm *RelayManager) pullSimple(ctx context.Context, body io.Reader, stream *Stream) {
187-
buf := make([]byte, 8192)
188+
buf := make([]byte, 16384)
188189
for {
189190
select {
190191
case <-ctx.Done():
191192
return
192193
default:
193194
n, err := body.Read(buf)
194195
if n > 0 {
195-
stream.Broadcast(buf[:n], rm.relay)
196+
data := buf[:n]
197+
stream.Broadcast(data, rm.relay)
198+
199+
// Sniff for Opus metadata (Vorbis comments) in Ogg pages
200+
// Look for "OpusTags" magic
201+
if idx := bytes.Index(data, []byte("OpusTags")); idx != -1 {
202+
// Found tags! Extract title if possible
203+
// Skip "OpusTags" (8 bytes)
204+
tagsData := data[idx+8:]
205+
if len(tagsData) > 8 {
206+
// Simple sniffer for "TITLE="
207+
tagsStr := string(tagsData)
208+
if strings.Contains(tagsStr, "TITLE=") {
209+
title := strings.Split(tagsStr, "TITLE=")[1]
210+
// Titles in Ogg are often null-terminated or limited by length
211+
// For simplicity, we just take a reasonable chunk and trim
212+
if len(title) > 100 {
213+
title = title[:100]
214+
}
215+
// Clean up
216+
title = strings.Map(func(r rune) rune {
217+
if r < 32 || r > 126 {
218+
return -1
219+
}
220+
return r
221+
}, title)
222+
if title != "" {
223+
stream.SetCurrentSong(title, rm.relay)
224+
}
225+
}
226+
}
227+
}
196228
}
197229
if err != nil {
198230
return

relay/relay.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,15 @@ type Stream struct {
121121
BytesDropped int64 // Track total bytes dropped due to slow listeners
122122
CurrentSong string
123123
Public bool
124-
Visible bool
125-
IsTranscoded bool // True if this stream is an output of a transcoder
126-
IsOggStream bool // Pre-calculated for speed
127-
128-
LastDataReceived time.Time
129-
130-
131-
OggHead []byte // Store Ogg headers for Opus/Ogg streams
132-
OggHeaderOffset int64 // Absolute buffer offset where headers end
133-
LastPageOffset int64 // Absolute offset of the last valid Ogg page start
124+
Visible bool
125+
IsTranscoded bool // True if this stream is an output of a transcoder
126+
IsOggStream bool // Pre-calculated for speed
127+
128+
LastDataReceived time.Time
129+
130+
OggHead []byte // Store Ogg headers for Opus/Ogg streams
131+
OggHeaderOffset int64 // Absolute buffer offset where headers end
132+
LastPageOffset int64 // Absolute offset of the last valid Ogg page start
134133
PageOffsets []int64 // Circular list of last ~100 page starts
135134
PageIndex int
136135

@@ -152,7 +151,7 @@ func (r *StreamReader) Read(p []byte) (int, error) {
152151
for {
153152
n, next, skipped := r.Stream.Buffer.ReadAt(r.Offset, p)
154153
if skipped && r.Stream.IsOggStream {
155-
// If we were skipped forward because the buffer wrapped around,
154+
// If we were skipped forward because the buffer wrapped around,
156155
// we MUST re-align to the next Ogg page start.
157156
r.Offset = r.Stream.Buffer.FindNextPageBoundary(next)
158157
continue // Retry read at aligned offset
@@ -248,9 +247,8 @@ func (r *Relay) GetStream(mount string) (*Stream, bool) {
248247
}
249248

250249
func (r *Relay) UpdateMetadata(mount, song string) {
251-
if st, ok := r.GetStream(mount); ok {
252-
st.SetCurrentSong(song, r)
253-
}
250+
st := r.GetOrCreateStream(mount)
251+
st.SetCurrentSong(song, r)
254252
}
255253

256254
// IsOgg returns true if the stream is Ogg-based (Ogg/Vorbis, Ogg/Opus, etc)
@@ -346,15 +344,19 @@ func (s *Stream) Subscribe(id string, burstSize int) (int64, chan struct{}) {
346344
// For Ogg/Opus, align to the oldest known page boundary within the valid buffer range
347345
if s.IsOggStream {
348346
validStart := s.Buffer.Head - s.Buffer.Size
349-
if validStart < 0 { validStart = 0 }
350-
351-
// If we have an OggHead persistent storage, we want to start reading
347+
if validStart < 0 {
348+
validStart = 0
349+
}
350+
351+
// If we have an OggHead persistent storage, we want to start reading
352352
// from the Buffer AFTER the initial headers to avoid duplicates.
353353
if s.OggHeaderOffset > start {
354354
start = s.OggHeaderOffset
355355
}
356356

357-
if start < validStart { start = validStart }
357+
if start < validStart {
358+
start = validStart
359+
}
358360

359361
bestAlign := s.LastPageOffset
360362
found := false
@@ -373,7 +375,7 @@ func (s *Stream) Subscribe(id string, burstSize int) (int64, chan struct{}) {
373375
start = s.Buffer.Head // Fallback to now if nothing valid found
374376
}
375377
}
376-
378+
377379
// Ensure we don't go back further than the buffer allows
378380
if s.Buffer.Head-start > s.Buffer.Size {
379381
start = s.Buffer.Head - s.Buffer.Size
@@ -498,7 +500,7 @@ func (s *Stream) Snapshot() StreamStats {
498500

499501
bi := atomic.LoadInt64(&s.BytesIn)
500502
bd := atomic.LoadInt64(&s.BytesDropped)
501-
503+
502504
// Health calculation
503505
// 1. Loss-based health
504506
health := 100.0
@@ -548,7 +550,6 @@ func (s *Stream) Snapshot() StreamStats {
548550
}
549551
}
550552

551-
552553
// uptimeLocked returns the formatted uptime string assuming the lock is already held
553554
func (s *Stream) uptimeLocked() string {
554555
d := time.Since(s.Started).Round(time.Second)

0 commit comments

Comments
 (0)