aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-12 15:59:55 +0200
committerMax Kellermann <max@duempel.org>2008-09-12 15:59:55 +0200
commit1333c392444fad9dc23f4d7a07c39fd275e72e4e (patch)
treed0c3cba11f78ede0d263d446bb2aae46392b332b /src/audioOutputs
parentf482f83eb893314dbfe84ec04b017c7c469d8ca3 (diff)
downloadmpd-1333c392444fad9dc23f4d7a07c39fd275e72e4e.tar.gz
mpd-1333c392444fad9dc23f4d7a07c39fd275e72e4e.tar.xz
mpd-1333c392444fad9dc23f4d7a07c39fd275e72e4e.zip
shout: added struct _ogg_vorbis_data
Preparing the merge of Eric Wollesen's patch "Refactor and cleanup of shout Ogg and MP3 audio outputs": we declare one of the struct types here, to make the merge smoother.
Diffstat (limited to '')
-rw-r--r--src/audioOutputs/audioOutput_shout.h12
-rw-r--r--src/audioOutputs/audioOutput_shout_ogg.c117
2 files changed, 73 insertions, 56 deletions
diff --git a/src/audioOutputs/audioOutput_shout.h b/src/audioOutputs/audioOutput_shout.h
index f145d7566..295a7e14f 100644
--- a/src/audioOutputs/audioOutput_shout.h
+++ b/src/audioOutputs/audioOutput_shout.h
@@ -35,10 +35,7 @@ typedef struct _shout_buffer {
size_t max_len;
} shout_buffer;
-struct shout_data {
- shout_t *shout_conn;
- int shout_error;
-
+typedef struct _ogg_vorbis_data {
ogg_stream_state os;
ogg_page og;
ogg_packet op;
@@ -50,6 +47,13 @@ struct shout_data {
vorbis_block vb;
vorbis_info vi;
vorbis_comment vc;
+} ogg_vorbis_data;
+
+struct shout_data {
+ shout_t *shout_conn;
+ int shout_error;
+
+ ogg_vorbis_data od;
float quality;
int bitrate;
diff --git a/src/audioOutputs/audioOutput_shout_ogg.c b/src/audioOutputs/audioOutput_shout_ogg.c
index cda6e5533..c5b08a8c8 100644
--- a/src/audioOutputs/audioOutput_shout_ogg.c
+++ b/src/audioOutputs/audioOutput_shout_ogg.c
@@ -22,30 +22,32 @@
#include "../utils.h"
-static void add_tag(struct shout_data *sd, const char *name, char *value)
+static void add_tag(ogg_vorbis_data *od, const char *name, char *value)
{
if (value) {
union const_hack u;
u.in = name;
- vorbis_comment_add_tag(&(sd->vc), u.out, value);
+ vorbis_comment_add_tag(&od->vc, u.out, value);
}
}
void copy_tag_to_vorbis_comment(struct shout_data *sd)
{
+ ogg_vorbis_data *od = &sd->od;
+
if (sd->tag) {
int i;
for (i = 0; i < sd->tag->numOfItems; i++) {
switch (sd->tag->items[i]->type) {
case TAG_ITEM_ARTIST:
- add_tag(sd, "ARTIST", sd->tag->items[i]->value);
+ add_tag(od, "ARTIST", sd->tag->items[i]->value);
break;
case TAG_ITEM_ALBUM:
- add_tag(sd, "ALBUM", sd->tag->items[i]->value);
+ add_tag(od, "ALBUM", sd->tag->items[i]->value);
break;
case TAG_ITEM_TITLE:
- add_tag(sd, "TITLE", sd->tag->items[i]->value);
+ add_tag(od, "TITLE", sd->tag->items[i]->value);
break;
default:
break;
@@ -81,85 +83,92 @@ static int copy_ogg_buffer_to_shout_buffer(ogg_page *og,
static int flush_ogg_buffer(struct shout_data *sd)
{
shout_buffer *buf = &sd->buf;
+ ogg_vorbis_data *od = &sd->od;
int ret = 0;
- if (ogg_stream_flush(&sd->os, &sd->og))
- ret = copy_ogg_buffer_to_shout_buffer(&sd->og, buf);
+ if (ogg_stream_flush(&od->os, &od->og))
+ ret = copy_ogg_buffer_to_shout_buffer(&od->og, buf);
return ret;
}
int send_ogg_vorbis_header(struct shout_data *sd)
{
- vorbis_analysis_headerout(&(sd->vd), &(sd->vc), &(sd->header_main),
- &(sd->header_comments),
- &(sd->header_codebooks));
+ ogg_vorbis_data *od = &sd->od;
+
+ vorbis_analysis_headerout(&od->vd, &od->vc,
+ &od->header_main,
+ &od->header_comments,
+ &od->header_codebooks);
- ogg_stream_packetin(&(sd->os), &(sd->header_main));
- ogg_stream_packetin(&(sd->os), &(sd->header_comments));
- ogg_stream_packetin(&(sd->os), &(sd->header_codebooks));
+ ogg_stream_packetin(&od->os, &od->header_main);
+ ogg_stream_packetin(&od->os, &od->header_comments);
+ ogg_stream_packetin(&od->os, &od->header_codebooks);
return flush_ogg_buffer(sd);
}
-static void finish_encoder(struct shout_data *sd)
+static void finish_encoder(ogg_vorbis_data *od)
{
- vorbis_analysis_wrote(&sd->vd, 0);
+ vorbis_analysis_wrote(&od->vd, 0);
- while (vorbis_analysis_blockout(&sd->vd, &sd->vb) == 1) {
- vorbis_analysis(&sd->vb, NULL);
- vorbis_bitrate_addblock(&sd->vb);
- while (vorbis_bitrate_flushpacket(&sd->vd, &sd->op)) {
- ogg_stream_packetin(&sd->os, &sd->op);
+ while (vorbis_analysis_blockout(&od->vd, &od->vb) == 1) {
+ vorbis_analysis(&od->vb, NULL);
+ vorbis_bitrate_addblock(&od->vb);
+ while (vorbis_bitrate_flushpacket(&od->vd, &od->op)) {
+ ogg_stream_packetin(&od->os, &od->op);
}
}
}
int shout_ogg_encoder_clear_encoder(struct shout_data *sd)
{
+ ogg_vorbis_data *od = &sd->od;
int ret;
- finish_encoder(sd);
- if ((ret = ogg_stream_pageout(&sd->os, &sd->og)))
- copy_ogg_buffer_to_shout_buffer(&sd->og, &sd->buf);
+ finish_encoder(od);
+ if ((ret = ogg_stream_pageout(&od->os, &od->og)))
+ copy_ogg_buffer_to_shout_buffer(&od->og, &sd->buf);
- vorbis_comment_clear(&sd->vc);
- ogg_stream_clear(&sd->os);
- vorbis_block_clear(&sd->vb);
- vorbis_dsp_clear(&sd->vd);
- vorbis_info_clear(&sd->vi);
+ vorbis_comment_clear(&od->vc);
+ ogg_stream_clear(&od->os);
+ vorbis_block_clear(&od->vb);
+ vorbis_dsp_clear(&od->vd);
+ vorbis_info_clear(&od->vi);
return ret;
}
static int reinit_encoder(struct shout_data *sd)
{
- vorbis_info_init(&(sd->vi));
+ ogg_vorbis_data *od = &sd->od;
+
+ vorbis_info_init(&od->vi);
if (sd->quality >= -1.0) {
- if (0 != vorbis_encode_init_vbr(&(sd->vi),
+ if (0 != vorbis_encode_init_vbr(&od->vi,
sd->audio_format.channels,
sd->audio_format.sampleRate,
sd->quality * 0.1)) {
ERROR("problem setting up vorbis encoder for shout\n");
- vorbis_info_clear(&(sd->vi));
+ vorbis_info_clear(&od->vi);
return -1;
}
} else {
- if (0 != vorbis_encode_init(&(sd->vi),
+ if (0 != vorbis_encode_init(&od->vi,
sd->audio_format.channels,
sd->audio_format.sampleRate, -1.0,
sd->bitrate * 1000, -1.0)) {
ERROR("problem setting up vorbis encoder for shout\n");
- vorbis_info_clear(&(sd->vi));
+ vorbis_info_clear(&od->vi);
return -1;
}
}
- vorbis_analysis_init(&(sd->vd), &(sd->vi));
- vorbis_block_init(&(sd->vd), &(sd->vb));
- ogg_stream_init(&(sd->os), rand());
- vorbis_comment_init(&(sd->vc));
+ vorbis_analysis_init(&od->vd, &od->vi);
+ vorbis_block_init(&od->vd, &od->vb);
+ ogg_stream_init(&od->os, rand());
+ vorbis_comment_init(&od->vc);
return 0;
}
@@ -179,19 +188,22 @@ int init_encoder(struct shout_data *sd)
int shout_ogg_encoder_send_metadata(struct shout_data * sd)
{
+ ogg_vorbis_data *od = &sd->od;
+
shout_ogg_encoder_clear_encoder(sd);
if (reinit_encoder(sd))
return 0;
copy_tag_to_vorbis_comment(sd);
- vorbis_analysis_headerout(&(sd->vd), &(sd->vc), &(sd->header_main),
- &(sd->header_comments),
- &(sd->header_codebooks));
+ vorbis_analysis_headerout(&od->vd, &od->vc,
+ &od->header_main,
+ &od->header_comments,
+ &od->header_codebooks);
- ogg_stream_packetin(&(sd->os), &(sd->header_main));
- ogg_stream_packetin(&(sd->os), &(sd->header_comments));
- ogg_stream_packetin(&(sd->os), &(sd->header_codebooks));
+ ogg_stream_packetin(&od->os, &od->header_main);
+ ogg_stream_packetin(&od->os, &od->header_comments);
+ ogg_stream_packetin(&od->os, &od->header_codebooks);
flush_ogg_buffer(sd);
@@ -207,9 +219,10 @@ void shout_ogg_encoder_encode(struct shout_data *sd,
float **vorbbuf;
unsigned int samples;
int bytes = sd->audio_format.bits / 8;
+ ogg_vorbis_data *od = &sd->od;
samples = size / (bytes * sd->audio_format.channels);
- vorbbuf = vorbis_analysis_buffer(&(sd->vd), samples);
+ vorbbuf = vorbis_analysis_buffer(&od->vd, samples);
/* this is for only 16-bit audio */
@@ -220,19 +233,19 @@ void shout_ogg_encoder_encode(struct shout_data *sd,
}
}
- vorbis_analysis_wrote(&(sd->vd), samples);
+ vorbis_analysis_wrote(&od->vd, samples);
- while (1 == vorbis_analysis_blockout(&(sd->vd), &(sd->vb))) {
- vorbis_analysis(&(sd->vb), NULL);
- vorbis_bitrate_addblock(&(sd->vb));
+ while (1 == vorbis_analysis_blockout(&od->vd, &od->vb)) {
+ vorbis_analysis(&od->vb, NULL);
+ vorbis_bitrate_addblock(&od->vb);
- while (vorbis_bitrate_flushpacket(&(sd->vd), &(sd->op))) {
- ogg_stream_packetin(&(sd->os), &(sd->op));
+ while (vorbis_bitrate_flushpacket(&od->vd, &od->op)) {
+ ogg_stream_packetin(&od->os, &od->op);
}
}
- if (ogg_stream_pageout(&sd->os, &sd->og))
- copy_ogg_buffer_to_shout_buffer(&sd->og, buf);
+ if (ogg_stream_pageout(&od->os, &od->og))
+ copy_ogg_buffer_to_shout_buffer(&od->og, buf);
}
#endif