shout: clear buffer before calling the encoder
Always assume the buffer is empty before calling the encoder. Always flush the buffer immediately after there has been added something. This reduces the risk of buffer overruns, because there will never be a "rest" in the current buffer.
This commit is contained in:
parent
7fc25ad567
commit
1ac328b553
1
NEWS
1
NEWS
|
@ -50,6 +50,7 @@ ver 0.14.2 (2009/??/??)
|
||||||
- shout: switch to blocking mode
|
- shout: switch to blocking mode
|
||||||
- shout: use libshout's synchronization
|
- shout: use libshout's synchronization
|
||||||
- shout: don't postpone metadata
|
- shout: don't postpone metadata
|
||||||
|
- shout: clear buffer before calling the encoder
|
||||||
* mapper: remove trailing slashes from music_directory
|
* mapper: remove trailing slashes from music_directory
|
||||||
* player: set player error when output device fails
|
* player: set player error when output device fails
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@ static int shout_mp3_encoder_clear_encoder(struct shout_data *sd)
|
||||||
struct shout_buffer *buf = &sd->buf;
|
struct shout_buffer *buf = &sd->buf;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((ret = lame_encode_flush(ld->gfp, buf->data + buf->len,
|
ret = lame_encode_flush(ld->gfp, buf->data, sizeof(buf->data));
|
||||||
buf->len)) < 0)
|
if (ret < 0)
|
||||||
g_warning("error flushing lame buffers\n");
|
g_warning("error flushing lame buffers\n");
|
||||||
|
|
||||||
lame_close(ld->gfp);
|
lame_close(ld->gfp);
|
||||||
|
@ -164,7 +164,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd,
|
||||||
|
|
||||||
bytes_out = lame_encode_buffer_float(ld->gfp, left, right,
|
bytes_out = lame_encode_buffer_float(ld->gfp, left, right,
|
||||||
samples, buf->data,
|
samples, buf->data,
|
||||||
sizeof(buf->data) - buf->len);
|
sizeof(buf->data));
|
||||||
|
|
||||||
g_free(left);
|
g_free(left);
|
||||||
if (right != left)
|
if (right != left)
|
||||||
|
|
|
@ -75,23 +75,14 @@ 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 (sizeof(buf->data) - buf->len >= (size_t)og->header_len) {
|
if ((size_t)og->header_len + (size_t)og->body_len > sizeof(buf->data)) {
|
||||||
memcpy(buf->data + buf->len,
|
|
||||||
og->header, og->header_len);
|
|
||||||
buf->len += og->header_len;
|
|
||||||
} else {
|
|
||||||
g_warning("%s: not enough buffer space!\n", __func__);
|
g_warning("%s: not enough buffer space!\n", __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sizeof(buf->data) - buf->len >= (size_t)og->body_len) {
|
memcpy(buf->data, og->header, og->header_len);
|
||||||
memcpy(buf->data + buf->len,
|
memcpy(buf->data + og->header_len, og->body, og->body_len);
|
||||||
og->body, og->body_len);
|
buf->len = og->header_len + og->body_len;
|
||||||
buf->len += og->body_len;
|
|
||||||
} else {
|
|
||||||
g_warning("%s: not enough buffer space!\n", __func__);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,6 @@ static struct shout_data *new_shout_data(void)
|
||||||
ret->bitrate = -1;
|
ret->bitrate = -1;
|
||||||
ret->quality = -2.0;
|
ret->quality = -2.0;
|
||||||
ret->timeout = DEFAULT_CONN_TIMEOUT;
|
ret->timeout = DEFAULT_CONN_TIMEOUT;
|
||||||
ret->buf.len = 0;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -287,13 +286,14 @@ static int write_page(struct shout_data *sd)
|
||||||
err = shout_send(sd->shout_conn, sd->buf.data, sd->buf.len);
|
err = shout_send(sd->shout_conn, sd->buf.data, sd->buf.len);
|
||||||
if (handle_shout_error(sd, err) < 0)
|
if (handle_shout_error(sd, err) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
sd->buf.len = 0;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_shout_conn(struct shout_data * sd)
|
static void close_shout_conn(struct shout_data * sd)
|
||||||
{
|
{
|
||||||
|
sd->buf.len = 0;
|
||||||
|
|
||||||
if (sd->encoder->clear_encoder_func(sd))
|
if (sd->encoder->clear_encoder_func(sd))
|
||||||
write_page(sd);
|
write_page(sd);
|
||||||
|
|
||||||
|
@ -359,6 +359,8 @@ static int open_shout_conn(void *data)
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
sd->buf.len = 0;
|
||||||
|
|
||||||
if (sd->encoder->init_encoder_func(sd) < 0) {
|
if (sd->encoder->init_encoder_func(sd) < 0) {
|
||||||
shout_close(sd->shout_conn);
|
shout_close(sd->shout_conn);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -386,6 +388,8 @@ my_shout_play(void *data, const char *chunk, size_t size)
|
||||||
{
|
{
|
||||||
struct shout_data *sd = (struct shout_data *)data;
|
struct shout_data *sd = (struct shout_data *)data;
|
||||||
|
|
||||||
|
sd->buf.len = 0;
|
||||||
|
|
||||||
if (sd->encoder->encode_func(sd, chunk, size))
|
if (sd->encoder->encode_func(sd, chunk, size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -410,6 +414,7 @@ static void my_shout_set_tag(void *data,
|
||||||
char song[1024];
|
char song[1024];
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
|
sd->buf.len = 0;
|
||||||
sd->tag = tag;
|
sd->tag = tag;
|
||||||
ret = sd->encoder->send_metadata_func(sd, song, sizeof(song));
|
ret = sd->encoder->send_metadata_func(sd, song, sizeof(song));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|
Loading…
Reference in New Issue