Fix ESP32 audio dropouts and improve streaming reliability
FLAC encoder now tracks frame numbers and reuses per-channel sample buffers to reduce allocations. Client dialer always frees the active slot on release so mDNS re-emissions can reconnect cleanly. Server send buffer uses drop-oldest instead of hard failure, with lateness tracking. Added engine stats logging (chunks/sec, kbps) and writer diagnostics. UI simplified to a single play/pause toggle that auto-starts playback on preset selection. Added --preset CLI flag for headless startup. Removed stale systemd service files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
14
third_party/sendspin-go/pkg/sendspin/server.go
vendored
14
third_party/sendspin-go/pkg/sendspin/server.go
vendored
@@ -96,6 +96,12 @@ type Server struct {
|
||||
audioSource AudioSource
|
||||
consecutiveReadErrs int
|
||||
|
||||
// Accumulates bytes-on-wire across one streamAudio rate window
|
||||
// (encoded chunk size, not raw PCM) so the periodic stats line can
|
||||
// report both chunks/sec and kbps. Touched only from the streamAudio
|
||||
// goroutine so no locking needed.
|
||||
lastWindowBytes int64
|
||||
|
||||
mdnsManager *discovery.Manager
|
||||
|
||||
// server-initiated discovery dialer cancel
|
||||
@@ -554,12 +560,19 @@ func (s *Server) clientWriter(c *ServerClient) {
|
||||
for {
|
||||
select {
|
||||
case msg := <-c.sendChan:
|
||||
queueDepth := len(c.sendChan)
|
||||
switch v := msg.(type) {
|
||||
case []byte:
|
||||
c.conn.SetWriteDeadline(time.Now().Add(writeDeadline))
|
||||
wStart := time.Now()
|
||||
if err := c.conn.WriteMessage(websocket.BinaryMessage, v); err != nil {
|
||||
log.Printf("clientWriter %s: binary write error: %v (queue %d)", c.name, err, queueDepth)
|
||||
return
|
||||
}
|
||||
if wDur := time.Since(wStart); wDur > 5*time.Millisecond || queueDepth > 5 {
|
||||
log.Printf("clientWriter %s: %s for %d bytes (queue %d)",
|
||||
c.name, wDur.Round(time.Microsecond), len(v), queueDepth)
|
||||
}
|
||||
default:
|
||||
data, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
@@ -567,6 +580,7 @@ func (s *Server) clientWriter(c *ServerClient) {
|
||||
}
|
||||
c.conn.SetWriteDeadline(time.Now().Add(writeDeadline))
|
||||
if err := c.conn.WriteMessage(websocket.TextMessage, data); err != nil {
|
||||
log.Printf("clientWriter %s: text write error: %v", c.name, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user