mod_shout: Rework our_mpg123_new() to handle error cases correctly and to clean up the code

Keeping parameter handling quirks for backwards compatibility reasons.

Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
Stefan Knoblich 2013-07-11 03:12:25 +02:00
parent 90021b2953
commit cb554fb023
1 changed files with 26 additions and 35 deletions

View File

@ -60,52 +60,43 @@ static struct {
mpg123_handle *our_mpg123_new(const char *decoder, int *error) mpg123_handle *our_mpg123_new(const char *decoder, int *error)
{ {
mpg123_handle *mh;
const char *arch = "auto"; const char *arch = "auto";
const char *err = NULL;
mpg123_handle *mh;
int x64 = 0; int x64 = 0;
int rc = 0; int rc = 0;
const char *err = NULL;
if (*globals.decoder || globals.outscale || globals.vol) { if (*globals.decoder) {
if (*globals.decoder) { arch = globals.decoder;
arch = globals.decoder; }
} #ifndef WIN32
if ((mh = mpg123_new(arch, &rc))) { else if (sizeof(void *) == 4) {
if (rc) { arch = "i586";
err = mpg123_plain_strerror(rc);
}
if (globals.outscale) {
mpg123_param(mh, MPG123_OUTSCALE, globals.outscale, 0);
}
if (globals.vol) {
mpg123_volume(mh, globals.vol);
}
}
} else { } else {
x64 = 1;
#ifdef WIN32 }
x64++;
#else #else
if (sizeof(void *) == 4) { x64 = 1;
arch = "i586";
} else {
x64++;
}
#endif #endif
mh = mpg123_new(arch, &rc);
if (!mh) {
err = mpg123_plain_strerror(rc);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error allocating mpg123 handle! %s\n", switch_str_nil(err));
return NULL;
}
if ((mh = mpg123_new(arch, &rc))) { /* NOTE: keeping the globals.decoder check here for behaviour backwards compat - stkn */
if (rc) { if (*globals.decoder || globals.outscale || globals.vol) {
err = mpg123_plain_strerror(rc); if (globals.outscale) {
} mpg123_param(mh, MPG123_OUTSCALE, globals.outscale, 0);
if (x64) {
mpg123_param(mh, MPG123_OUTSCALE, 8192, 0);
}
} }
if (globals.vol) {
mpg123_volume(mh, globals.vol);
}
} else if (x64) {
mpg123_param(mh, MPG123_OUTSCALE, 8192, 0);
} }
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error allocating mpg123 handle! %s\n", err);
}
return mh; return mh;
} }