Spotify: tell cspot when a new track becomes audible
The Mac dropped the device soon after the first track change: we never
called SpircHandler::notifyAudioReachedPlayback(), so cspot's queue did
not advance and the state sent to Spotify stalled.
- The data callback records a boundary (output write position, track
id) when the track id changes; the session loop (<= 200 ms) calls
notifyAudioReachedPlayback(id) once playback (ring read position)
passes it, and notifyAudioEnded() after DEPLETED once the buffer is
empty. PLAYBACK_START clears boundaries (next data is a new one),
seek/flush drop pending ones.
- audio_ring exposes its write/read frame counters (wrap-safe compare).
- Verified: 10 min on the Mac without a disconnect, every track change
notified ("track audible, Spotify notified"), app shows the playing
track (switches up to ~3-5 s early), 0 underruns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,16 @@ size_t audio_ring_read(int32_t *frames, size_t n)
|
||||
return n;
|
||||
}
|
||||
|
||||
uint32_t audio_ring_written(void)
|
||||
{
|
||||
return __atomic_load_n(&s_wr, __ATOMIC_ACQUIRE);
|
||||
}
|
||||
|
||||
uint32_t audio_ring_read_pos(void)
|
||||
{
|
||||
return __atomic_load_n(&s_rd, __ATOMIC_ACQUIRE);
|
||||
}
|
||||
|
||||
void audio_ring_flush(void)
|
||||
{
|
||||
__atomic_store_n(&s_rd, __atomic_load_n(&s_wr, __ATOMIC_ACQUIRE), __ATOMIC_RELEASE);
|
||||
|
||||
@@ -13,3 +13,6 @@ size_t audio_ring_space(void); // frames that can be written
|
||||
size_t audio_ring_write(const int32_t *frames, size_t n); // producer; returns frames written
|
||||
size_t audio_ring_read(int32_t *frames, size_t n); // consumer; returns frames read
|
||||
void audio_ring_flush(void); // consumer side: drop everything buffered
|
||||
// Monotonic frame counters (wrap at 2^32): frames written so far / read (played) so far.
|
||||
uint32_t audio_ring_written(void);
|
||||
uint32_t audio_ring_read_pos(void);
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ esp_err_t player_init(void)
|
||||
if (!s_spotify_conv) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
spotify_init(spotify_pcm, spotify_event);
|
||||
spotify_init(spotify_pcm, spotify_event, audio_ring_written, audio_ring_read_pos);
|
||||
aes67_ota_on_update(on_ota);
|
||||
err = hls_start(decoder_feed);
|
||||
if (err != ESP_OK) {
|
||||
|
||||
Reference in New Issue
Block a user