shout: copy the audio_format, instead of taking a pointer
Storing pointers to immutable audio_format structs isn't worth it, because the struct itself isn't much larger than the pointer. Since the shout plugin requires the user to configure a fixed audio format, we can simply copy it in myShout_initDriver().
This commit is contained in:
parent
3aa4564b56
commit
544c13cc89
@ -64,8 +64,8 @@ typedef struct _ShoutData {
|
|||||||
|
|
||||||
Timer *timer;
|
Timer *timer;
|
||||||
|
|
||||||
/* just a pointer to audioOutput->outAudioFormat */
|
/* the configured audio format */
|
||||||
const struct audio_format *audioFormat;
|
struct audio_format audio_format;
|
||||||
} ShoutData;
|
} ShoutData;
|
||||||
|
|
||||||
static ShoutData *newShoutData(void)
|
static ShoutData *newShoutData(void)
|
||||||
@ -81,7 +81,6 @@ static ShoutData *newShoutData(void)
|
|||||||
ret->timeout = DEFAULT_CONN_TIMEOUT;
|
ret->timeout = DEFAULT_CONN_TIMEOUT;
|
||||||
ret->connAttempts = 0;
|
ret->connAttempts = 0;
|
||||||
ret->lastAttempt = 0;
|
ret->lastAttempt = 0;
|
||||||
ret->audioFormat = NULL;
|
|
||||||
ret->timer = NULL;
|
ret->timer = NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -196,7 +195,7 @@ static int myShout_initDriver(struct audio_output *audioOutput,
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkBlockParam("format");
|
checkBlockParam("format");
|
||||||
sd->audioFormat = &audioOutput->outAudioFormat;
|
sd->audio_format = audioOutput->outAudioFormat;
|
||||||
|
|
||||||
if (shout_set_host(sd->shoutConn, host) != SHOUTERR_SUCCESS ||
|
if (shout_set_host(sd->shoutConn, host) != SHOUTERR_SUCCESS ||
|
||||||
shout_set_port(sd->shoutConn, port) != SHOUTERR_SUCCESS ||
|
shout_set_port(sd->shoutConn, port) != SHOUTERR_SUCCESS ||
|
||||||
@ -242,10 +241,10 @@ static int myShout_initDriver(struct audio_output *audioOutput,
|
|||||||
char temp[11];
|
char temp[11];
|
||||||
memset(temp, 0, sizeof(temp));
|
memset(temp, 0, sizeof(temp));
|
||||||
|
|
||||||
snprintf(temp, sizeof(temp), "%d", sd->audioFormat->channels);
|
snprintf(temp, sizeof(temp), "%d", sd->audio_format.channels);
|
||||||
shout_set_audio_info(sd->shoutConn, SHOUT_AI_CHANNELS, temp);
|
shout_set_audio_info(sd->shoutConn, SHOUT_AI_CHANNELS, temp);
|
||||||
|
|
||||||
snprintf(temp, sizeof(temp), "%d", sd->audioFormat->sampleRate);
|
snprintf(temp, sizeof(temp), "%d", sd->audio_format.sampleRate);
|
||||||
|
|
||||||
shout_set_audio_info(sd->shoutConn, SHOUT_AI_SAMPLERATE, temp);
|
shout_set_audio_info(sd->shoutConn, SHOUT_AI_SAMPLERATE, temp);
|
||||||
|
|
||||||
@ -426,8 +425,8 @@ static int initEncoder(ShoutData * sd)
|
|||||||
|
|
||||||
if (sd->quality >= -1.0) {
|
if (sd->quality >= -1.0) {
|
||||||
if (0 != vorbis_encode_init_vbr(&(sd->vi),
|
if (0 != vorbis_encode_init_vbr(&(sd->vi),
|
||||||
sd->audioFormat->channels,
|
sd->audio_format.channels,
|
||||||
sd->audioFormat->sampleRate,
|
sd->audio_format.sampleRate,
|
||||||
sd->quality * 0.1)) {
|
sd->quality * 0.1)) {
|
||||||
ERROR("problem setting up vorbis encoder for shout\n");
|
ERROR("problem setting up vorbis encoder for shout\n");
|
||||||
vorbis_info_clear(&(sd->vi));
|
vorbis_info_clear(&(sd->vi));
|
||||||
@ -435,8 +434,8 @@ static int initEncoder(ShoutData * sd)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (0 != vorbis_encode_init(&(sd->vi),
|
if (0 != vorbis_encode_init(&(sd->vi),
|
||||||
sd->audioFormat->channels,
|
sd->audio_format.channels,
|
||||||
sd->audioFormat->sampleRate, -1.0,
|
sd->audio_format.sampleRate, -1.0,
|
||||||
sd->bitrate * 1000, -1.0)) {
|
sd->bitrate * 1000, -1.0)) {
|
||||||
ERROR("problem setting up vorbis encoder for shout\n");
|
ERROR("problem setting up vorbis encoder for shout\n");
|
||||||
vorbis_info_clear(&(sd->vi));
|
vorbis_info_clear(&(sd->vi));
|
||||||
@ -607,7 +606,7 @@ static int myShout_play(struct audio_output *audioOutput,
|
|||||||
ShoutData *sd = (ShoutData *) audioOutput->data;
|
ShoutData *sd = (ShoutData *) audioOutput->data;
|
||||||
float **vorbbuf;
|
float **vorbbuf;
|
||||||
unsigned int samples;
|
unsigned int samples;
|
||||||
int bytes = sd->audioFormat->bits / 8;
|
int bytes = sd->audio_format.bits / 8;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (!sd->timer->started)
|
if (!sd->timer->started)
|
||||||
@ -629,14 +628,14 @@ static int myShout_play(struct audio_output *audioOutput,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
samples = size / (bytes * sd->audioFormat->channels);
|
samples = size / (bytes * sd->audio_format.channels);
|
||||||
|
|
||||||
/* this is for only 16-bit audio */
|
/* this is for only 16-bit audio */
|
||||||
|
|
||||||
vorbbuf = vorbis_analysis_buffer(&(sd->vd), samples);
|
vorbbuf = vorbis_analysis_buffer(&(sd->vd), samples);
|
||||||
|
|
||||||
for (i = 0; i < samples; i++) {
|
for (i = 0; i < samples; i++) {
|
||||||
for (j = 0; j < sd->audioFormat->channels; j++) {
|
for (j = 0; j < sd->audio_format.channels; j++) {
|
||||||
vorbbuf[j][i] = (*((const mpd_sint16 *) playChunk)) / 32768.0;
|
vorbbuf[j][i] = (*((const mpd_sint16 *) playChunk)) / 32768.0;
|
||||||
playChunk += bytes;
|
playChunk += bytes;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user