shout: removed typedefs on structs and plugin methods
Don't typedef the structs at all. It is easier to forward-declare this way. Don't typedef methods. They are used exactly once, a few lines below.
This commit is contained in:
@@ -42,7 +42,7 @@ static void init_shout_encoder_plugins(void)
|
|||||||
shout_encoder_plugin_list = makeList(NULL, 0);
|
shout_encoder_plugin_list = makeList(NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_shout_encoder_plugin(shout_encoder_plugin * plugin)
|
static void load_shout_encoder_plugin(struct shout_encoder_plugin * plugin)
|
||||||
{
|
{
|
||||||
if (!plugin->name)
|
if (!plugin->name)
|
||||||
return;
|
return;
|
||||||
@@ -50,7 +50,7 @@ static void load_shout_encoder_plugin(shout_encoder_plugin * plugin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mpd_unused
|
mpd_unused
|
||||||
static void unload_shout_encoder_plugin(shout_encoder_plugin * plugin)
|
static void unload_shout_encoder_plugin(struct shout_encoder_plugin * plugin)
|
||||||
{
|
{
|
||||||
if (!plugin->name)
|
if (!plugin->name)
|
||||||
return;
|
return;
|
||||||
@@ -229,7 +229,7 @@ static int my_shout_init_driver(struct audio_output *audio_output,
|
|||||||
FATAL("couldn't find shout encoder plugin for \"%s\" "
|
FATAL("couldn't find shout encoder plugin for \"%s\" "
|
||||||
"at line %i\n", encoding, block_param->line);
|
"at line %i\n", encoding, block_param->line);
|
||||||
}
|
}
|
||||||
sd->encoder = (shout_encoder_plugin *) data;
|
sd->encoder = (struct shout_encoder_plugin *) data;
|
||||||
|
|
||||||
if (shout_set_host(sd->shout_conn, host) != SHOUTERR_SUCCESS ||
|
if (shout_set_host(sd->shout_conn, host) != SHOUTERR_SUCCESS ||
|
||||||
shout_set_port(sd->shout_conn, port) != SHOUTERR_SUCCESS ||
|
shout_set_port(sd->shout_conn, port) != SHOUTERR_SUCCESS ||
|
||||||
|
@@ -28,50 +28,43 @@
|
|||||||
|
|
||||||
#include <shout/shout.h>
|
#include <shout/shout.h>
|
||||||
|
|
||||||
#define DISABLED_SHOUT_ENCODER_PLUGIN(plugin) shout_encoder_plugin plugin;
|
#define DISABLED_SHOUT_ENCODER_PLUGIN(plugin) \
|
||||||
|
struct shout_encoder_plugin plugin;
|
||||||
|
|
||||||
typedef struct shout_data shout_data;
|
struct shout_data;
|
||||||
|
|
||||||
typedef int (*shout_encoder_clear_encoder_func) (shout_data * sd);
|
struct shout_encoder_plugin {
|
||||||
typedef int (*shout_encoder_encode_func) (shout_data * sd,
|
|
||||||
const char * chunk,
|
|
||||||
size_t len);
|
|
||||||
typedef void (*shout_encoder_finish_func) (shout_data * sd);
|
|
||||||
typedef int (*shout_encoder_init_func) (shout_data * sd);
|
|
||||||
typedef int (*shout_encoder_init_encoder_func) (shout_data * sd);
|
|
||||||
/* Called when there is a new MpdTag to encode into the stream. If
|
|
||||||
this function returns non-zero, then the resulting song will be
|
|
||||||
passed to the shout server as metadata. This allows the Ogg
|
|
||||||
encoder to send metadata via Vorbis comments in the stream, while
|
|
||||||
an MP3 encoder can use the Shout Server's metadata API. */
|
|
||||||
typedef int (*shout_encoder_send_metadata_func) (shout_data * sd,
|
|
||||||
char * song,
|
|
||||||
size_t size);
|
|
||||||
|
|
||||||
typedef struct _shout_encoder_plugin {
|
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned int shout_format;
|
unsigned int shout_format;
|
||||||
|
|
||||||
shout_encoder_clear_encoder_func clear_encoder_func;
|
int (*clear_encoder_func)(struct shout_data *sd);
|
||||||
shout_encoder_encode_func encode_func;
|
int (*encode_func)(struct shout_data *sd,
|
||||||
shout_encoder_finish_func finish_func;
|
const char *chunk, size_t len);
|
||||||
shout_encoder_init_func init_func;
|
void (*finish_func)(struct shout_data *sd);
|
||||||
shout_encoder_init_encoder_func init_encoder_func;
|
int (*init_func)(struct shout_data *sd);
|
||||||
shout_encoder_send_metadata_func send_metadata_func;
|
int (*init_encoder_func) (struct shout_data *sd);
|
||||||
} shout_encoder_plugin;
|
/* Called when there is a new MpdTag to encode into the
|
||||||
|
stream. If this function returns non-zero, then the
|
||||||
|
resulting song will be passed to the shout server as
|
||||||
|
metadata. This allows the Ogg encoder to send metadata via
|
||||||
|
Vorbis comments in the stream, while an MP3 encoder can use
|
||||||
|
the Shout Server's metadata API. */
|
||||||
|
int (*send_metadata_func)(struct shout_data *sd,
|
||||||
|
char *song, size_t size);
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct _shout_buffer {
|
struct shout_buffer {
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t max_len;
|
size_t max_len;
|
||||||
} shout_buffer;
|
};
|
||||||
|
|
||||||
struct shout_data {
|
struct shout_data {
|
||||||
shout_t *shout_conn;
|
shout_t *shout_conn;
|
||||||
shout_metadata_t *shout_meta;
|
shout_metadata_t *shout_meta;
|
||||||
int shout_error;
|
int shout_error;
|
||||||
|
|
||||||
shout_encoder_plugin *encoder;
|
struct shout_encoder_plugin *encoder;
|
||||||
void *encoder_data;
|
void *encoder_data;
|
||||||
|
|
||||||
float quality;
|
float quality;
|
||||||
@@ -91,11 +84,11 @@ struct shout_data {
|
|||||||
/* the configured audio format */
|
/* the configured audio format */
|
||||||
struct audio_format audio_format;
|
struct audio_format audio_format;
|
||||||
|
|
||||||
shout_buffer buf;
|
struct shout_buffer buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern shout_encoder_plugin shout_mp3_encoder;
|
extern struct shout_encoder_plugin shout_mp3_encoder;
|
||||||
extern shout_encoder_plugin shout_ogg_encoder;
|
extern struct shout_encoder_plugin shout_ogg_encoder;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -24,26 +24,26 @@
|
|||||||
#include "audioOutput_shout.h"
|
#include "audioOutput_shout.h"
|
||||||
#include <lame/lame.h>
|
#include <lame/lame.h>
|
||||||
|
|
||||||
typedef struct _lame_data {
|
struct lame_data {
|
||||||
lame_global_flags *gfp;
|
lame_global_flags *gfp;
|
||||||
} lame_data;
|
};
|
||||||
|
|
||||||
|
|
||||||
static int shout_mp3_encoder_init(shout_data * sd)
|
static int shout_mp3_encoder_init(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
lame_data *ld;
|
struct lame_data *ld;
|
||||||
|
|
||||||
if (NULL == (ld = xmalloc(sizeof(lame_data))))
|
if (NULL == (ld = xmalloc(sizeof(*ld))))
|
||||||
FATAL("error initializing lame encoder data\n");
|
FATAL("error initializing lame encoder data\n");
|
||||||
sd->encoder_data = ld;
|
sd->encoder_data = ld;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shout_mp3_encoder_clear_encoder(shout_data * sd)
|
static int shout_mp3_encoder_clear_encoder(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
lame_data *ld = (lame_data *)sd->encoder_data;
|
struct lame_data *ld = (struct lame_data *)sd->encoder_data;
|
||||||
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,
|
if ((ret = lame_encode_flush(ld->gfp, buf->data + buf->len,
|
||||||
@@ -53,17 +53,17 @@ static int shout_mp3_encoder_clear_encoder(shout_data * sd)
|
|||||||
return (ret > 0);
|
return (ret > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shout_mp3_encoder_finish(shout_data * sd)
|
static void shout_mp3_encoder_finish(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
lame_data *ld = (lame_data *)sd->encoder_data;
|
struct lame_data *ld = (struct lame_data *)sd->encoder_data;
|
||||||
|
|
||||||
lame_close(ld->gfp);
|
lame_close(ld->gfp);
|
||||||
ld->gfp = NULL;
|
ld->gfp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shout_mp3_encoder_init_encoder(shout_data * sd)
|
static int shout_mp3_encoder_init_encoder(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
lame_data *ld = (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");
|
ERROR("error initializing lame encoder for shout\n");
|
||||||
@@ -104,7 +104,7 @@ static int shout_mp3_encoder_init_encoder(shout_data * sd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shout_mp3_encoder_send_metadata(shout_data * sd,
|
static int shout_mp3_encoder_send_metadata(struct shout_data *sd,
|
||||||
char * song, size_t size)
|
char * song, size_t size)
|
||||||
{
|
{
|
||||||
char artist[size];
|
char artist[size];
|
||||||
@@ -133,16 +133,16 @@ static int shout_mp3_encoder_send_metadata(shout_data * sd,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shout_mp3_encoder_encode(shout_data * sd,
|
static int shout_mp3_encoder_encode(struct shout_data *sd,
|
||||||
const char * chunk, size_t len)
|
const char * chunk, size_t len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int j;
|
int j;
|
||||||
float (*lamebuf)[2];
|
float (*lamebuf)[2];
|
||||||
shout_buffer *buf = &(sd->buf);
|
struct shout_buffer *buf = &(sd->buf);
|
||||||
unsigned int samples;
|
unsigned int samples;
|
||||||
int bytes = sd->audio_format.bits / 8;
|
int bytes = sd->audio_format.bits / 8;
|
||||||
lame_data *ld = (lame_data *)sd->encoder_data;
|
struct lame_data *ld = (struct lame_data *)sd->encoder_data;
|
||||||
int bytes_out;
|
int bytes_out;
|
||||||
|
|
||||||
samples = len / (bytes * sd->audio_format.channels);
|
samples = len / (bytes * sd->audio_format.channels);
|
||||||
@@ -174,8 +174,7 @@ static int shout_mp3_encoder_encode(shout_data * sd,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct shout_encoder_plugin shout_mp3_encoder = {
|
||||||
shout_encoder_plugin shout_mp3_encoder = {
|
|
||||||
"mp3",
|
"mp3",
|
||||||
SHOUT_FORMAT_MP3,
|
SHOUT_FORMAT_MP3,
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
#include <vorbis/vorbisenc.h>
|
#include <vorbis/vorbisenc.h>
|
||||||
|
|
||||||
typedef struct _ogg_vorbis_data {
|
struct ogg_vorbis_data {
|
||||||
ogg_stream_state os;
|
ogg_stream_state os;
|
||||||
ogg_page og;
|
ogg_page og;
|
||||||
ogg_packet op;
|
ogg_packet op;
|
||||||
@@ -35,9 +35,9 @@ typedef struct _ogg_vorbis_data {
|
|||||||
vorbis_block vb;
|
vorbis_block vb;
|
||||||
vorbis_info vi;
|
vorbis_info vi;
|
||||||
vorbis_comment vc;
|
vorbis_comment vc;
|
||||||
} ogg_vorbis_data;
|
};
|
||||||
|
|
||||||
static void add_tag(ogg_vorbis_data *od, const char *name, char *value)
|
static void add_tag(struct ogg_vorbis_data *od, const char *name, char *value)
|
||||||
{
|
{
|
||||||
if (value) {
|
if (value) {
|
||||||
union const_hack u;
|
union const_hack u;
|
||||||
@@ -48,7 +48,7 @@ static void add_tag(ogg_vorbis_data *od, const char *name, char *value)
|
|||||||
|
|
||||||
static void copy_tag_to_vorbis_comment(struct shout_data *sd)
|
static void copy_tag_to_vorbis_comment(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
|
|
||||||
if (sd->tag) {
|
if (sd->tag) {
|
||||||
int i;
|
int i;
|
||||||
@@ -73,7 +73,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,
|
||||||
shout_buffer *buf)
|
struct shout_buffer *buf)
|
||||||
{
|
{
|
||||||
if (buf->max_len - buf->len >= (size_t)og->header_len) {
|
if (buf->max_len - buf->len >= (size_t)og->header_len) {
|
||||||
memcpy(buf->data + buf->len,
|
memcpy(buf->data + buf->len,
|
||||||
@@ -98,8 +98,8 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og,
|
|||||||
|
|
||||||
static int flush_ogg_buffer(struct shout_data *sd)
|
static int flush_ogg_buffer(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
shout_buffer *buf = &sd->buf;
|
struct shout_buffer *buf = &sd->buf;
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (ogg_stream_flush(&od->os, &od->og))
|
if (ogg_stream_flush(&od->os, &od->og))
|
||||||
@@ -110,7 +110,7 @@ static int flush_ogg_buffer(struct shout_data *sd)
|
|||||||
|
|
||||||
static int send_ogg_vorbis_header(struct shout_data *sd)
|
static int send_ogg_vorbis_header(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
|
|
||||||
vorbis_analysis_headerout(&od->vd, &od->vc,
|
vorbis_analysis_headerout(&od->vd, &od->vc,
|
||||||
&od->header_main,
|
&od->header_main,
|
||||||
@@ -124,7 +124,7 @@ static int send_ogg_vorbis_header(struct shout_data *sd)
|
|||||||
return flush_ogg_buffer(sd);
|
return flush_ogg_buffer(sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void finish_encoder(ogg_vorbis_data *od)
|
static void finish_encoder(struct ogg_vorbis_data *od)
|
||||||
{
|
{
|
||||||
vorbis_analysis_wrote(&od->vd, 0);
|
vorbis_analysis_wrote(&od->vd, 0);
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ static void finish_encoder(ogg_vorbis_data *od)
|
|||||||
|
|
||||||
static int shout_ogg_encoder_clear_encoder(struct shout_data *sd)
|
static int shout_ogg_encoder_clear_encoder(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
finish_encoder(od);
|
finish_encoder(od);
|
||||||
@@ -157,7 +157,7 @@ static int shout_ogg_encoder_clear_encoder(struct shout_data *sd)
|
|||||||
|
|
||||||
static void shout_ogg_encoder_finish(struct shout_data *sd)
|
static void shout_ogg_encoder_finish(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
|
|
||||||
if (od) {
|
if (od) {
|
||||||
free(od);
|
free(od);
|
||||||
@@ -167,9 +167,9 @@ 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)
|
||||||
{
|
{
|
||||||
ogg_vorbis_data *od;
|
struct ogg_vorbis_data *od;
|
||||||
|
|
||||||
if (NULL == (od = xmalloc(sizeof(ogg_vorbis_data))))
|
if (NULL == (od = xmalloc(sizeof(*od))))
|
||||||
FATAL("error initializing ogg vorbis encoder data\n");
|
FATAL("error initializing ogg vorbis encoder data\n");
|
||||||
sd->encoder_data = od;
|
sd->encoder_data = od;
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ static int shout_ogg_encoder_init(struct shout_data *sd)
|
|||||||
|
|
||||||
static int reinit_encoder(struct shout_data *sd)
|
static int reinit_encoder(struct shout_data *sd)
|
||||||
{
|
{
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
|
|
||||||
vorbis_info_init(&od->vi);
|
vorbis_info_init(&od->vi);
|
||||||
|
|
||||||
@@ -227,7 +227,7 @@ static int shout_ogg_encoder_send_metadata(struct shout_data *sd,
|
|||||||
mpd_unused char * song,
|
mpd_unused char * song,
|
||||||
mpd_unused size_t size)
|
mpd_unused size_t size)
|
||||||
{
|
{
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
|
|
||||||
shout_ogg_encoder_clear_encoder(sd);
|
shout_ogg_encoder_clear_encoder(sd);
|
||||||
if (reinit_encoder(sd))
|
if (reinit_encoder(sd))
|
||||||
@@ -252,13 +252,13 @@ static int shout_ogg_encoder_send_metadata(struct shout_data *sd,
|
|||||||
static int shout_ogg_encoder_encode(struct shout_data *sd,
|
static int shout_ogg_encoder_encode(struct shout_data *sd,
|
||||||
const char *chunk, size_t size)
|
const char *chunk, size_t size)
|
||||||
{
|
{
|
||||||
shout_buffer *buf = &sd->buf;
|
struct shout_buffer *buf = &sd->buf;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int j;
|
int j;
|
||||||
float **vorbbuf;
|
float **vorbbuf;
|
||||||
unsigned int samples;
|
unsigned int samples;
|
||||||
int bytes = sd->audio_format.bits / 8;
|
int bytes = sd->audio_format.bits / 8;
|
||||||
ogg_vorbis_data *od = (ogg_vorbis_data *)sd->encoder_data;
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
||||||
|
|
||||||
samples = size / (bytes * sd->audio_format.channels);
|
samples = size / (bytes * sd->audio_format.channels);
|
||||||
vorbbuf = vorbis_analysis_buffer(&od->vd, samples);
|
vorbbuf = vorbis_analysis_buffer(&od->vd, samples);
|
||||||
@@ -289,7 +289,7 @@ static int shout_ogg_encoder_encode(struct shout_data *sd,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shout_encoder_plugin shout_ogg_encoder = {
|
struct shout_encoder_plugin shout_ogg_encoder = {
|
||||||
"ogg",
|
"ogg",
|
||||||
SHOUT_FORMAT_VORBIS,
|
SHOUT_FORMAT_VORBIS,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user