From 70720d34454fb52a2596a793b72b5d18773f7b8f Mon Sep 17 00:00:00 2001 From: philippe44 Date: Tue, 2 Jan 2024 00:35:47 -0800 Subject: [PATCH] don't allocate segments - release --- components/squeezelite/opus.c | 1 + components/squeezelite/squeezelite.h | 2 +- components/squeezelite/stream.c | 15 +++++++-------- components/squeezelite/vorbis.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/squeezelite/opus.c b/components/squeezelite/opus.c index 0c87d3e8..9312e40e 100644 --- a/components/squeezelite/opus.c +++ b/components/squeezelite/opus.c @@ -227,6 +227,7 @@ static int read_opus_header(void) { } else if (u->status == OGG_COMMENT_HEADER) { // don't consume VorbisComment which could be a huge packet, just skip it if (!OG(&go, page_packets, &u->page)) continue; + LOG_INFO("[%p]: comment skipped successfully", ctx); done = 1; } } diff --git a/components/squeezelite/squeezelite.h b/components/squeezelite/squeezelite.h index bbb27d23..7df800d0 100644 --- a/components/squeezelite/squeezelite.h +++ b/components/squeezelite/squeezelite.h @@ -583,7 +583,7 @@ struct streamstate { struct { enum { STREAM_OGG_OFF, STREAM_OGG_SYNC, STREAM_OGG_HEADER, STREAM_OGG_SEGMENTS, STREAM_OGG_PAGE } state; u32_t want, miss, match; - u8_t* data; + u8_t* data, segments[255]; #pragma pack(push, 1) struct { char pattern[4]; diff --git a/components/squeezelite/stream.c b/components/squeezelite/stream.c index 5f952bb1..2752957d 100644 --- a/components/squeezelite/stream.c +++ b/components/squeezelite/stream.c @@ -59,7 +59,7 @@ is enough and much faster than a mutex static bool polling; static sockfd fd; -struct streamstate stream; +struct EXT_RAM_ATTR streamstate stream; #if USE_SSL static SSL_CTX *SSLctx; @@ -148,8 +148,8 @@ static bool running = true; static void _disconnect(stream_state state, disconnect_code disconnect) { stream.state = state; stream.disconnect = disconnect; - if (stream.ogg.state == STREAM_OGG_HEADER && stream.ogg.data) free(stream.ogg.data); - stream.ogg.data = NULL; + if (stream.ogg.state == STREAM_OGG_PAGE && stream.ogg.data) free(stream.ogg.data); + stream.ogg.data = NULL; #if USE_SSL if (ssl) { SSL_shutdown(ssl); @@ -205,7 +205,7 @@ static void stream_ogg(size_t n) { case STREAM_OGG_HEADER: if (!memcmp(stream.ogg.header.pattern, "OggS", 4)) { stream.ogg.miss = stream.ogg.want = stream.ogg.header.count; - stream.ogg.data = malloc(stream.ogg.miss); + stream.ogg.data = stream.ogg.segments; stream.ogg.state = STREAM_OGG_SEGMENTS; } else { stream.ogg.state = STREAM_OGG_SYNC; @@ -220,11 +220,10 @@ static void stream_ogg(size_t n) { if (stream.ogg.header.granule == 0) { // granule 0 means a new stream, so let's look into it stream.ogg.state = STREAM_OGG_PAGE; - stream.ogg.data = realloc(stream.ogg.data, stream.ogg.want); + stream.ogg.data = malloc(stream.ogg.want); } else { // otherwise, jump over data stream.ogg.state = STREAM_OGG_SYNC; - free(stream.ogg.data); stream.ogg.data = NULL; } break; @@ -726,8 +725,8 @@ bool stream_disconnect(void) { disc = true; } stream.state = STOPPED; - if (stream.ogg.state == STREAM_OGG_HEADER && stream.ogg.data) free(stream.ogg.data); - stream.ogg.data = NULL; + if (stream.ogg.state == STREAM_OGG_PAGE && stream.ogg.data) free(stream.ogg.data); + stream.ogg.data = NULL; UNLOCK; return disc; } diff --git a/components/squeezelite/vorbis.c b/components/squeezelite/vorbis.c index 0bb041c4..a330a303 100644 --- a/components/squeezelite/vorbis.c +++ b/components/squeezelite/vorbis.c @@ -242,7 +242,7 @@ static int read_vorbis_header(void) { OV(&gv, comment_init, &v->comment); v->comment.vendor = "N/A"; fetch = true; - LOG_INFO("comment skipped succesfully"); + LOG_INFO("comment skipped successfully"); // because of lack of page alignment, we might have the setup page already fully in if (packets == 1) continue;