Commit 265b8fff authored by Max Kellermann's avatar Max Kellermann

shout: make the shout_buffer static

Since the buffer size is known at compile time, we can save an indirection by declaring it as a char array instead of a pointer. That saves an extra allocation, and we can calculate with the compile-time constant sizeof(data) instead of the attribute "max_len".
parent ebd19499
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#define CONN_ATTEMPT_INTERVAL 60 #define CONN_ATTEMPT_INTERVAL 60
#define DEFAULT_CONN_TIMEOUT 2 #define DEFAULT_CONN_TIMEOUT 2
#define SHOUT_BUF_SIZE 8192
static int shout_init_count; static int shout_init_count;
static const struct shout_encoder_plugin *const shout_encoder_plugins[] = { static const struct shout_encoder_plugin *const shout_encoder_plugins[] = {
...@@ -68,9 +66,6 @@ static struct shout_data *new_shout_data(void) ...@@ -68,9 +66,6 @@ static struct shout_data *new_shout_data(void)
ret->conn_attempts = 0; ret->conn_attempts = 0;
ret->last_attempt = 0; ret->last_attempt = 0;
ret->timer = NULL; ret->timer = NULL;
ret->buf.data = xmalloc(sizeof(unsigned char) *
SHOUT_BUF_SIZE);
ret->buf.max_len = SHOUT_BUF_SIZE;
clear_shout_buffer(ret); clear_shout_buffer(ret);
return ret; return ret;
...@@ -84,8 +79,6 @@ static void free_shout_data(struct shout_data *sd) ...@@ -84,8 +79,6 @@ static void free_shout_data(struct shout_data *sd)
shout_free(sd->shout_conn); shout_free(sd->shout_conn);
if (sd->tag) if (sd->tag)
tag_free(sd->tag); tag_free(sd->tag);
if (sd->buf.data)
free(sd->buf.data);
if (sd->timer) if (sd->timer)
timer_free(sd->timer); timer_free(sd->timer);
......
...@@ -54,9 +54,8 @@ struct shout_encoder_plugin { ...@@ -54,9 +54,8 @@ struct shout_encoder_plugin {
}; };
struct shout_buffer { struct shout_buffer {
unsigned char *data; unsigned char data[8192];
size_t len; size_t len;
size_t max_len;
}; };
struct shout_data { struct shout_data {
......
...@@ -160,7 +160,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd, ...@@ -160,7 +160,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd,
bytes_out = lame_encode_buffer_float(ld->gfp, lamebuf[0], lamebuf[1], bytes_out = lame_encode_buffer_float(ld->gfp, lamebuf[0], lamebuf[1],
samples, buf->data, samples, buf->data,
buf->max_len - buf->len); sizeof(buf->data) - buf->len);
free(lamebuf); free(lamebuf);
if (0 > bytes_out) { if (0 > bytes_out) {
......
...@@ -75,7 +75,7 @@ static void copy_tag_to_vorbis_comment(struct shout_data *sd) ...@@ -75,7 +75,7 @@ static void copy_tag_to_vorbis_comment(struct shout_data *sd)
static int copy_ogg_buffer_to_shout_buffer(ogg_page *og, static int copy_ogg_buffer_to_shout_buffer(ogg_page *og,
struct shout_buffer *buf) struct shout_buffer *buf)
{ {
if (buf->max_len - buf->len >= (size_t)og->header_len) { if (sizeof(buf->data) - buf->len >= (size_t)og->header_len) {
memcpy(buf->data + buf->len, memcpy(buf->data + buf->len,
og->header, og->header_len); og->header, og->header_len);
buf->len += og->header_len; buf->len += og->header_len;
...@@ -84,7 +84,7 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og, ...@@ -84,7 +84,7 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og,
return -1; return -1;
} }
if (buf->max_len - buf->len >= (size_t)og->body_len) { if (sizeof(buf->data) - buf->len >= (size_t)og->body_len) {
memcpy(buf->data + buf->len, memcpy(buf->data + buf->len,
og->body, og->body_len); og->body, og->body_len);
buf->len += og->body_len; buf->len += og->body_len;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment