don't allocate segments - release

This commit is contained in:
philippe44
2024-01-02 00:35:47 -08:00
parent 4abe1304e8
commit 70720d3445
4 changed files with 10 additions and 10 deletions

View File

@@ -227,6 +227,7 @@ static int read_opus_header(void) {
} else if (u->status == OGG_COMMENT_HEADER) { } else if (u->status == OGG_COMMENT_HEADER) {
// don't consume VorbisComment which could be a huge packet, just skip it // don't consume VorbisComment which could be a huge packet, just skip it
if (!OG(&go, page_packets, &u->page)) continue; if (!OG(&go, page_packets, &u->page)) continue;
LOG_INFO("[%p]: comment skipped successfully", ctx);
done = 1; done = 1;
} }
} }

View File

@@ -583,7 +583,7 @@ struct streamstate {
struct { struct {
enum { STREAM_OGG_OFF, STREAM_OGG_SYNC, STREAM_OGG_HEADER, STREAM_OGG_SEGMENTS, STREAM_OGG_PAGE } state; enum { STREAM_OGG_OFF, STREAM_OGG_SYNC, STREAM_OGG_HEADER, STREAM_OGG_SEGMENTS, STREAM_OGG_PAGE } state;
u32_t want, miss, match; u32_t want, miss, match;
u8_t* data; u8_t* data, segments[255];
#pragma pack(push, 1) #pragma pack(push, 1)
struct { struct {
char pattern[4]; char pattern[4];

View File

@@ -59,7 +59,7 @@ is enough and much faster than a mutex
static bool polling; static bool polling;
static sockfd fd; static sockfd fd;
struct streamstate stream; struct EXT_RAM_ATTR streamstate stream;
#if USE_SSL #if USE_SSL
static SSL_CTX *SSLctx; static SSL_CTX *SSLctx;
@@ -148,8 +148,8 @@ static bool running = true;
static void _disconnect(stream_state state, disconnect_code disconnect) { static void _disconnect(stream_state state, disconnect_code disconnect) {
stream.state = state; stream.state = state;
stream.disconnect = disconnect; stream.disconnect = disconnect;
if (stream.ogg.state == STREAM_OGG_HEADER && stream.ogg.data) free(stream.ogg.data); if (stream.ogg.state == STREAM_OGG_PAGE && stream.ogg.data) free(stream.ogg.data);
stream.ogg.data = NULL; stream.ogg.data = NULL;
#if USE_SSL #if USE_SSL
if (ssl) { if (ssl) {
SSL_shutdown(ssl); SSL_shutdown(ssl);
@@ -205,7 +205,7 @@ static void stream_ogg(size_t n) {
case STREAM_OGG_HEADER: case STREAM_OGG_HEADER:
if (!memcmp(stream.ogg.header.pattern, "OggS", 4)) { if (!memcmp(stream.ogg.header.pattern, "OggS", 4)) {
stream.ogg.miss = stream.ogg.want = stream.ogg.header.count; 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; stream.ogg.state = STREAM_OGG_SEGMENTS;
} else { } else {
stream.ogg.state = STREAM_OGG_SYNC; stream.ogg.state = STREAM_OGG_SYNC;
@@ -220,11 +220,10 @@ static void stream_ogg(size_t n) {
if (stream.ogg.header.granule == 0) { if (stream.ogg.header.granule == 0) {
// granule 0 means a new stream, so let's look into it // granule 0 means a new stream, so let's look into it
stream.ogg.state = STREAM_OGG_PAGE; stream.ogg.state = STREAM_OGG_PAGE;
stream.ogg.data = realloc(stream.ogg.data, stream.ogg.want); stream.ogg.data = malloc(stream.ogg.want);
} else { } else {
// otherwise, jump over data // otherwise, jump over data
stream.ogg.state = STREAM_OGG_SYNC; stream.ogg.state = STREAM_OGG_SYNC;
free(stream.ogg.data);
stream.ogg.data = NULL; stream.ogg.data = NULL;
} }
break; break;
@@ -726,8 +725,8 @@ bool stream_disconnect(void) {
disc = true; disc = true;
} }
stream.state = STOPPED; stream.state = STOPPED;
if (stream.ogg.state == STREAM_OGG_HEADER && stream.ogg.data) free(stream.ogg.data); if (stream.ogg.state == STREAM_OGG_PAGE && stream.ogg.data) free(stream.ogg.data);
stream.ogg.data = NULL; stream.ogg.data = NULL;
UNLOCK; UNLOCK;
return disc; return disc;
} }

View File

@@ -242,7 +242,7 @@ static int read_vorbis_header(void) {
OV(&gv, comment_init, &v->comment); OV(&gv, comment_init, &v->comment);
v->comment.vendor = "N/A"; v->comment.vendor = "N/A";
fetch = true; 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 // because of lack of page alignment, we might have the setup page already fully in
if (packets == 1) continue; if (packets == 1) continue;