Browse Source

don't allocate segments - release

philippe44 1 year ago
parent
commit
70720d3445

+ 1 - 0
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;
 		}
 	}

+ 1 - 1
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];

+ 7 - 8
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;
 }

+ 1 - 1
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;