Commit be60ff83 authored by Max Kellermann's avatar Max Kellermann

shout: use GLib instead of utils.h/log.h

parent 125dad71
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
*/ */
#include "shout_plugin.h" #include "shout_plugin.h"
#include "../utils.h"
#include <lame/lame.h> #include <lame/lame.h>
#include <stdlib.h>
struct lame_data { struct lame_data {
lame_global_flags *gfp; lame_global_flags *gfp;
...@@ -28,10 +28,8 @@ struct lame_data { ...@@ -28,10 +28,8 @@ struct lame_data {
static int shout_mp3_encoder_init(struct shout_data *sd) static int shout_mp3_encoder_init(struct shout_data *sd)
{ {
struct lame_data *ld; struct lame_data *ld = g_new(struct lame_data, 1);
if (NULL == (ld = xmalloc(sizeof(*ld))))
FATAL("error initializing lame encoder data\n");
sd->encoder_data = ld; sd->encoder_data = ld;
return 0; return 0;
...@@ -45,7 +43,7 @@ static int shout_mp3_encoder_clear_encoder(struct shout_data *sd) ...@@ -45,7 +43,7 @@ static int shout_mp3_encoder_clear_encoder(struct shout_data *sd)
if ((ret = lame_encode_flush(ld->gfp, buf->data + buf->len, if ((ret = lame_encode_flush(ld->gfp, buf->data + buf->len,
buf->len)) < 0) buf->len)) < 0)
ERROR("error flushing lame buffers\n"); g_warning("error flushing lame buffers\n");
return (ret > 0); return (ret > 0);
} }
...@@ -63,40 +61,40 @@ static int shout_mp3_encoder_init_encoder(struct shout_data *sd) ...@@ -63,40 +61,40 @@ static int shout_mp3_encoder_init_encoder(struct shout_data *sd)
struct lame_data *ld = (struct lame_data *)sd->encoder_data; struct lame_data *ld = (struct lame_data *)sd->encoder_data;
if (NULL == (ld->gfp = lame_init())) { if (NULL == (ld->gfp = lame_init())) {
ERROR("error initializing lame encoder for shout\n"); g_warning("error initializing lame encoder for shout\n");
return -1; return -1;
} }
if (sd->quality >= -1.0) { if (sd->quality >= -1.0) {
if (0 != lame_set_VBR(ld->gfp, vbr_rh)) { if (0 != lame_set_VBR(ld->gfp, vbr_rh)) {
ERROR("error setting lame VBR mode\n"); g_warning("error setting lame VBR mode\n");
return -1; return -1;
} }
if (0 != lame_set_VBR_q(ld->gfp, sd->quality)) { if (0 != lame_set_VBR_q(ld->gfp, sd->quality)) {
ERROR("error setting lame VBR quality\n"); g_warning("error setting lame VBR quality\n");
return -1; return -1;
} }
} else { } else {
if (0 != lame_set_brate(ld->gfp, sd->bitrate)) { if (0 != lame_set_brate(ld->gfp, sd->bitrate)) {
ERROR("error setting lame bitrate\n"); g_warning("error setting lame bitrate\n");
return -1; return -1;
} }
} }
if (0 != lame_set_num_channels(ld->gfp, if (0 != lame_set_num_channels(ld->gfp,
sd->audio_format.channels)) { sd->audio_format.channels)) {
ERROR("error setting lame num channels\n"); g_warning("error setting lame num channels\n");
return -1; return -1;
} }
if (0 != lame_set_in_samplerate(ld->gfp, if (0 != lame_set_in_samplerate(ld->gfp,
sd->audio_format.sample_rate)) { sd->audio_format.sample_rate)) {
ERROR("error setting lame sample rate\n"); g_warning("error setting lame sample rate\n");
return -1; return -1;
} }
if (0 > lame_init_params(ld->gfp)) if (0 > lame_init_params(ld->gfp))
FATAL("error initializing lame params\n"); g_error("error initializing lame params\n");
return 0; return 0;
} }
...@@ -144,7 +142,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd, ...@@ -144,7 +142,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd,
samples = len / (bytes * sd->audio_format.channels); samples = len / (bytes * sd->audio_format.channels);
/* rough estimate, from lame.h */ /* rough estimate, from lame.h */
lamebuf = xmalloc(sizeof(float) * (1.25 * samples + 7200)); lamebuf = g_malloc(sizeof(float) * (1.25 * samples + 7200));
/* this is for only 16-bit audio */ /* this is for only 16-bit audio */
...@@ -161,7 +159,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd, ...@@ -161,7 +159,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd,
free(lamebuf); free(lamebuf);
if (0 > bytes_out) { if (0 > bytes_out) {
ERROR("error encoding lame buffer for shout\n"); g_warning("error encoding lame buffer for shout\n");
lame_close(ld->gfp); lame_close(ld->gfp);
ld->gfp = NULL; ld->gfp = NULL;
return -1; return -1;
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
*/ */
#include "shout_plugin.h" #include "shout_plugin.h"
#include "../utils.h"
#include <vorbis/vorbisenc.h> #include <vorbis/vorbisenc.h>
#include <stdlib.h>
struct ogg_vorbis_data { struct ogg_vorbis_data {
ogg_stream_state os; ogg_stream_state os;
...@@ -80,7 +80,7 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og, ...@@ -80,7 +80,7 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og,
og->header, og->header_len); og->header, og->header_len);
buf->len += og->header_len; buf->len += og->header_len;
} else { } else {
ERROR("%s: not enough buffer space!\n", __func__); g_warning("%s: not enough buffer space!\n", __func__);
return -1; return -1;
} }
...@@ -89,7 +89,7 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og, ...@@ -89,7 +89,7 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og,
og->body, og->body_len); og->body, og->body_len);
buf->len += og->body_len; buf->len += og->body_len;
} else { } else {
ERROR("%s: not enough buffer space!\n", __func__); g_warning("%s: not enough buffer space!\n", __func__);
return -1; return -1;
} }
...@@ -167,10 +167,8 @@ static void shout_ogg_encoder_finish(struct shout_data *sd) ...@@ -167,10 +167,8 @@ static void shout_ogg_encoder_finish(struct shout_data *sd)
static int shout_ogg_encoder_init(struct shout_data *sd) static int shout_ogg_encoder_init(struct shout_data *sd)
{ {
struct ogg_vorbis_data *od; struct ogg_vorbis_data *od = g_new(struct ogg_vorbis_data, 1);
if (NULL == (od = xmalloc(sizeof(*od))))
FATAL("error initializing ogg vorbis encoder data\n");
sd->encoder_data = od; sd->encoder_data = od;
return 0; return 0;
...@@ -187,7 +185,7 @@ static int reinit_encoder(struct shout_data *sd) ...@@ -187,7 +185,7 @@ static int reinit_encoder(struct shout_data *sd)
sd->audio_format.channels, sd->audio_format.channels,
sd->audio_format.sample_rate, sd->audio_format.sample_rate,
sd->quality * 0.1)) { sd->quality * 0.1)) {
ERROR("error initializing vorbis vbr\n"); g_warning("error initializing vorbis vbr\n");
vorbis_info_clear(&od->vi); vorbis_info_clear(&od->vi);
return -1; return -1;
} }
...@@ -196,7 +194,7 @@ static int reinit_encoder(struct shout_data *sd) ...@@ -196,7 +194,7 @@ static int reinit_encoder(struct shout_data *sd)
sd->audio_format.channels, sd->audio_format.channels,
sd->audio_format.sample_rate, -1.0, sd->audio_format.sample_rate, -1.0,
sd->bitrate * 1000, -1.0)) { sd->bitrate * 1000, -1.0)) {
ERROR("error initializing vorbis encoder\n"); g_warning("error initializing vorbis encoder\n");
vorbis_info_clear(&od->vi); vorbis_info_clear(&od->vi);
return -1; return -1;
} }
...@@ -216,7 +214,7 @@ static int shout_ogg_encoder_init_encoder(struct shout_data *sd) ...@@ -216,7 +214,7 @@ static int shout_ogg_encoder_init_encoder(struct shout_data *sd)
return -1; return -1;
if (send_ogg_vorbis_header(sd)) { if (send_ogg_vorbis_header(sd)) {
ERROR("error sending ogg vorbis header for shout\n"); g_warning("error sending ogg vorbis header for shout\n");
return -1; return -1;
} }
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#include "shout_plugin.h" #include "shout_plugin.h"
#include "../utils.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#define CONN_ATTEMPT_INTERVAL 60 #define CONN_ATTEMPT_INTERVAL 60
#define DEFAULT_CONN_TIMEOUT 2 #define DEFAULT_CONN_TIMEOUT 2
...@@ -51,7 +51,7 @@ shout_encoder_plugin_get(const char *name) ...@@ -51,7 +51,7 @@ shout_encoder_plugin_get(const char *name)
static struct shout_data *new_shout_data(void) static struct shout_data *new_shout_data(void)
{ {
struct shout_data *ret = xmalloc(sizeof(*ret)); struct shout_data *ret = g_new(struct shout_data, 1);
ret->shout_conn = shout_new(); ret->shout_conn = shout_new();
ret->shout_meta = shout_metadata_new(); ret->shout_meta = shout_metadata_new();
...@@ -86,7 +86,7 @@ static void free_shout_data(struct shout_data *sd) ...@@ -86,7 +86,7 @@ static void free_shout_data(struct shout_data *sd)
#define check_block_param(name) { \ #define check_block_param(name) { \
block_param = getBlockParam(param, name); \ block_param = getBlockParam(param, name); \
if (!block_param) { \ if (!block_param) { \
FATAL("no \"%s\" defined for shout device defined at line " \ g_error("no \"%s\" defined for shout device defined at line " \
"%i\n", name, param->line); \ "%i\n", name, param->line); \
} \ } \
} }
...@@ -127,7 +127,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -127,7 +127,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
port = strtol(block_param->value, &test, 10); port = strtol(block_param->value, &test, 10);
if (*test != '\0' || port <= 0) { if (*test != '\0' || port <= 0) {
FATAL("shout port \"%s\" is not a positive integer, line %i\n", g_error("shout port \"%s\" is not a positive integer, line %i\n",
block_param->value, block_param->line); block_param->value, block_param->line);
} }
...@@ -155,7 +155,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -155,7 +155,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
sd->quality = strtod(block_param->value, &test); sd->quality = strtod(block_param->value, &test);
if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) { if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) {
FATAL("shout quality \"%s\" is not a number in the " g_error("shout quality \"%s\" is not a number in the "
"range -1 to 10, line %i\n", block_param->value, "range -1 to 10, line %i\n", block_param->value,
block_param->line); block_param->line);
} }
...@@ -163,7 +163,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -163,7 +163,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
block_param = getBlockParam(param, "bitrate"); block_param = getBlockParam(param, "bitrate");
if (block_param) { if (block_param) {
FATAL("quality (line %i) and bitrate (line %i) are " g_error("quality (line %i) and bitrate (line %i) are "
"both defined for shout output\n", line, "both defined for shout output\n", line,
block_param->line); block_param->line);
} }
...@@ -171,14 +171,14 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -171,14 +171,14 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
block_param = getBlockParam(param, "bitrate"); block_param = getBlockParam(param, "bitrate");
if (!block_param) { if (!block_param) {
FATAL("neither bitrate nor quality defined for shout " g_error("neither bitrate nor quality defined for shout "
"output at line %i\n", param->line); "output at line %i\n", param->line);
} }
sd->bitrate = strtol(block_param->value, &test, 10); sd->bitrate = strtol(block_param->value, &test, 10);
if (*test != '\0' || sd->bitrate <= 0) { if (*test != '\0' || sd->bitrate <= 0) {
FATAL("bitrate at line %i should be a positive integer " g_error("bitrate at line %i should be a positive integer "
"\n", block_param->line); "\n", block_param->line);
} }
} }
...@@ -195,7 +195,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -195,7 +195,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
else if (0 == strcmp(block_param->value, "ogg")) else if (0 == strcmp(block_param->value, "ogg"))
encoding = block_param->value; encoding = block_param->value;
else else
FATAL("shout encoding \"%s\" is not \"ogg\" or " g_error("shout encoding \"%s\" is not \"ogg\" or "
"\"mp3\", line %i\n", block_param->value, "\"mp3\", line %i\n", block_param->value,
block_param->line); block_param->line);
} else { } else {
...@@ -204,14 +204,14 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -204,14 +204,14 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
sd->encoder = shout_encoder_plugin_get(encoding); sd->encoder = shout_encoder_plugin_get(encoding);
if (sd->encoder == NULL) if (sd->encoder == NULL)
FATAL("couldn't find shout encoder plugin for \"%s\" " g_error("couldn't find shout encoder plugin for \"%s\" "
"at line %i\n", encoding, block_param->line); "at line %i\n", encoding, block_param->line);
block_param = getBlockParam(param, "protocol"); block_param = getBlockParam(param, "protocol");
if (block_param) { if (block_param) {
if (0 == strcmp(block_param->value, "shoutcast") && if (0 == strcmp(block_param->value, "shoutcast") &&
0 != strcmp(encoding, "mp3")) 0 != strcmp(encoding, "mp3"))
FATAL("you cannot stream \"%s\" to shoutcast, use mp3\n", g_error("you cannot stream \"%s\" to shoutcast, use mp3\n",
encoding); encoding);
else if (0 == strcmp(block_param->value, "shoutcast")) else if (0 == strcmp(block_param->value, "shoutcast"))
protocol = SHOUT_PROTOCOL_ICY; protocol = SHOUT_PROTOCOL_ICY;
...@@ -220,7 +220,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -220,7 +220,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
else if (0 == strcmp(block_param->value, "icecast2")) else if (0 == strcmp(block_param->value, "icecast2"))
protocol = SHOUT_PROTOCOL_HTTP; protocol = SHOUT_PROTOCOL_HTTP;
else else
FATAL("shout protocol \"%s\" is not \"shoutcast\" or " g_error("shout protocol \"%s\" is not \"shoutcast\" or "
"\"icecast1\"or " "\"icecast1\"or "
"\"icecast2\", line %i\n", block_param->value, "\"icecast2\", line %i\n", block_param->value,
block_param->line); block_param->line);
...@@ -240,7 +240,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -240,7 +240,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
!= SHOUTERR_SUCCESS || != SHOUTERR_SUCCESS ||
shout_set_protocol(sd->shout_conn, protocol) != SHOUTERR_SUCCESS || shout_set_protocol(sd->shout_conn, protocol) != SHOUTERR_SUCCESS ||
shout_set_agent(sd->shout_conn, "MPD") != SHOUTERR_SUCCESS) { shout_set_agent(sd->shout_conn, "MPD") != SHOUTERR_SUCCESS) {
FATAL("error configuring shout defined at line %i: %s\n", g_error("error configuring shout defined at line %i: %s\n",
param->line, shout_get_error(sd->shout_conn)); param->line, shout_get_error(sd->shout_conn));
} }
...@@ -249,21 +249,21 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -249,21 +249,21 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
if (block_param) { if (block_param) {
sd->timeout = (int)strtol(block_param->value, &test, 10); sd->timeout = (int)strtol(block_param->value, &test, 10);
if (*test != '\0' || sd->timeout <= 0) { if (*test != '\0' || sd->timeout <= 0) {
FATAL("shout timeout is not a positive integer, " g_error("shout timeout is not a positive integer, "
"line %i\n", block_param->line); "line %i\n", block_param->line);
} }
} }
block_param = getBlockParam(param, "genre"); block_param = getBlockParam(param, "genre");
if (block_param && shout_set_genre(sd->shout_conn, block_param->value)) { if (block_param && shout_set_genre(sd->shout_conn, block_param->value)) {
FATAL("error configuring shout defined at line %i: %s\n", g_error("error configuring shout defined at line %i: %s\n",
param->line, shout_get_error(sd->shout_conn)); param->line, shout_get_error(sd->shout_conn));
} }
block_param = getBlockParam(param, "description"); block_param = getBlockParam(param, "description");
if (block_param && shout_set_description(sd->shout_conn, if (block_param && shout_set_description(sd->shout_conn,
block_param->value)) { block_param->value)) {
FATAL("error configuring shout defined at line %i: %s\n", g_error("error configuring shout defined at line %i: %s\n",
param->line, shout_get_error(sd->shout_conn)); param->line, shout_get_error(sd->shout_conn));
} }
...@@ -290,7 +290,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output, ...@@ -290,7 +290,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
} }
if (sd->encoder->init_func(sd) != 0) if (sd->encoder->init_func(sd) != 0)
FATAL("shout: encoder plugin '%s' failed to initialize\n", g_error("shout: encoder plugin '%s' failed to initialize\n",
sd->encoder->name); sd->encoder->name);
return sd; return sd;
...@@ -303,14 +303,14 @@ static int handle_shout_error(struct shout_data *sd, int err) ...@@ -303,14 +303,14 @@ static int handle_shout_error(struct shout_data *sd, int err)
break; break;
case SHOUTERR_UNCONNECTED: case SHOUTERR_UNCONNECTED:
case SHOUTERR_SOCKET: case SHOUTERR_SOCKET:
ERROR("Lost shout connection to %s:%i: %s\n", g_warning("Lost shout connection to %s:%i: %s\n",
shout_get_host(sd->shout_conn), shout_get_host(sd->shout_conn),
shout_get_port(sd->shout_conn), shout_get_port(sd->shout_conn),
shout_get_error(sd->shout_conn)); shout_get_error(sd->shout_conn));
sd->shout_error = 1; sd->shout_error = 1;
return -1; return -1;
default: default:
ERROR("shout: connection to %s:%i error: %s\n", g_warning("shout: connection to %s:%i error: %s\n",
shout_get_host(sd->shout_conn), shout_get_host(sd->shout_conn),
shout_get_port(sd->shout_conn), shout_get_port(sd->shout_conn),
shout_get_error(sd->shout_conn)); shout_get_error(sd->shout_conn));
...@@ -346,7 +346,7 @@ static void close_shout_conn(struct shout_data * sd) ...@@ -346,7 +346,7 @@ static void close_shout_conn(struct shout_data * sd)
if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED && if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED &&
shout_close(sd->shout_conn) != SHOUTERR_SUCCESS) { shout_close(sd->shout_conn) != SHOUTERR_SUCCESS) {
ERROR("problem closing connection to shout server: %s\n", g_warning("problem closing connection to shout server: %s\n",
shout_get_error(sd->shout_conn)); shout_get_error(sd->shout_conn));
} }
...@@ -401,7 +401,7 @@ static int shout_connect(struct shout_data *sd) ...@@ -401,7 +401,7 @@ static int shout_connect(struct shout_data *sd)
if (state == SHOUTERR_BUSY && sd->conn_attempts != 0) { if (state == SHOUTERR_BUSY && sd->conn_attempts != 0) {
/* timeout waiting to connect */ /* timeout waiting to connect */
if ((t - sd->last_attempt) > sd->timeout) { if ((t - sd->last_attempt) > sd->timeout) {
ERROR("timeout connecting to shout server %s:%i " g_warning("timeout connecting to shout server %s:%i "
"(attempt %i)\n", "(attempt %i)\n",
shout_get_host(sd->shout_conn), shout_get_host(sd->shout_conn),
shout_get_port(sd->shout_conn), shout_get_port(sd->shout_conn),
...@@ -435,7 +435,7 @@ static int shout_connect(struct shout_data *sd) ...@@ -435,7 +435,7 @@ static int shout_connect(struct shout_data *sd)
case SHOUTERR_BUSY: case SHOUTERR_BUSY:
return 1; return 1;
default: default:
ERROR("problem opening connection to shout server %s:%i " g_warning("problem opening connection to shout server %s:%i "
"(attempt %i): %s\n", "(attempt %i): %s\n",
shout_get_host(sd->shout_conn), shout_get_host(sd->shout_conn),
shout_get_port(sd->shout_conn), shout_get_port(sd->shout_conn),
...@@ -496,7 +496,7 @@ static void send_metadata(struct shout_data * sd) ...@@ -496,7 +496,7 @@ static void send_metadata(struct shout_data * sd)
shout_metadata_add(sd->shout_meta, "song", song); shout_metadata_add(sd->shout_meta, "song", song);
if (SHOUTERR_SUCCESS != shout_set_metadata(sd->shout_conn, if (SHOUTERR_SUCCESS != shout_set_metadata(sd->shout_conn,
sd->shout_meta)) { sd->shout_meta)) {
ERROR("error setting shout metadata\n"); g_warning("error setting shout metadata\n");
return; return;
} }
} }
......
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include "../timer.h" #include "../timer.h"
#include <shout/shout.h> #include <shout/shout.h>
#include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "shout"
struct shout_data; struct shout_data;
......
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