1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Rework stream_setup()

This commit is contained in:
Moritz Grimm 2015-06-02 23:45:55 +02:00
parent b0eda7b48c
commit f367140d82
3 changed files with 112 additions and 104 deletions

View File

@ -1048,9 +1048,7 @@ main(int argc, char *argv[])
cfg_get_program_config_file()); cfg_get_program_config_file());
} }
shout = stream_setup(cfg_get_server_hostname(), if (NULL == (shout = stream_setup()))
cfg_get_server_port(), cfg_get_stream_mountpoint());
if (shout == NULL)
return (ez_shutdown(1)); return (ez_shutdown(1));
#ifdef HAVE_SIGNALS #ifdef HAVE_SIGNALS

View File

@ -82,139 +82,149 @@ strrcasecmp(const char *s, const char *sub)
} }
shout_t * shout_t *
stream_setup(const char *host, unsigned short port, const char *mount) stream_setup(void)
{ {
shout_t *shout = NULL; shout_t *shout;
if ((shout = shout_new()) == NULL) { if ((shout = shout_new()) == NULL) {
log_syserr(ERROR, ENOMEM, "shout_new"); log_syserr(ERROR, ENOMEM, "shout_new");
return (NULL); return (NULL);
} }
if (shout_set_host(shout, host) != SHOUTERR_SUCCESS) { switch (cfg_get_server_protocol()) {
log_error("shout_set_host: %s", case CFG_PROTO_HTTP:
shout_get_error(shout)); if (SHOUTERR_SUCCESS !=
shout_free(shout); shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP)) {
return (NULL); log_error("shout_set_protocol: %s",
shout_get_error(shout));
goto error;
}
break;
default:
log_error("unsupported protocol: %s",
cfg_get_server_protocol_str());
goto error;
} }
if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) { if (SHOUTERR_SUCCESS !=
log_error("shout_set_protocol: %s", shout_set_host(shout, cfg_get_server_hostname())) {
shout_get_error(shout)); log_error("shout_set_host: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
} }
if (shout_set_port(shout, port) != SHOUTERR_SUCCESS) { if (SHOUTERR_SUCCESS !=
log_error("shout_set_port: %s", shout_set_port(shout, (unsigned short)cfg_get_server_port())) {
shout_get_error(shout)); log_error("shout_set_port: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
} }
if (shout_set_password(shout, cfg_get_server_password()) != SHOUTERR_SUCCESS) { if (SHOUTERR_SUCCESS !=
log_error("shout_set_password: %s", shout_set_user(shout, cfg_get_server_user())) {
shout_get_error(shout)); log_error("shout_set_user: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
} }
if (shout_set_mount(shout, mount) != SHOUTERR_SUCCESS) { if (SHOUTERR_SUCCESS !=
log_error("shout_set_mount: %s", shout_set_password(shout, cfg_get_server_password())) {
shout_get_error(shout)); log_error("shout_set_password: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
}
if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
log_error("shout_set_user: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
} }
if (CFG_STREAM_MP3 == cfg_get_stream_format() && if (SHOUTERR_SUCCESS !=
shout_set_format(shout, SHOUT_FORMAT_MP3) != SHOUTERR_SUCCESS) { shout_set_mount(shout, cfg_get_stream_mountpoint())) {
log_error("shout_set_format(MP3): %s", log_error("shout_set_mount: %s", shout_get_error(shout));
shout_get_error(shout)); goto error;
shout_free(shout);
return (NULL);
}
if ((CFG_STREAM_VORBIS == cfg_get_stream_format() ||
CFG_STREAM_THEORA == cfg_get_stream_format()) &&
shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
log_error("shout_set_format(OGG): %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
} }
if (shout_set_user(shout, cfg_get_server_user()) != SHOUTERR_SUCCESS) { switch (cfg_get_stream_format()) {
log_error("shout_set_user: %s", case CFG_STREAM_VORBIS:
shout_get_error(shout)); case CFG_STREAM_THEORA:
shout_free(shout); if (SHOUTERR_SUCCESS !=
return (NULL); shout_set_format(shout, SHOUT_FORMAT_OGG)) {
log_error("shout_set_format: OGG: %s",
shout_get_error(shout));
goto error;
}
break;
case CFG_STREAM_MP3:
if (SHOUTERR_SUCCESS !=
shout_set_format(shout, SHOUT_FORMAT_MP3)) {
log_error("shout_set_format: MP3: %s",
shout_get_error(shout));
goto error;
}
break;
default:
log_error("unsupported stream format: %s",
cfg_get_stream_format_str());
goto error;
} }
if (cfg_get_stream_name() && if (cfg_get_stream_name() &&
shout_set_name(shout, cfg_get_stream_name()) != SHOUTERR_SUCCESS) { SHOUTERR_SUCCESS !=
log_error("shout_set_name: %s", shout_set_name(shout, cfg_get_stream_name())) {
shout_get_error(shout)); log_error("shout_set_name: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
} }
if (cfg_get_stream_url() && if (cfg_get_stream_url() &&
shout_set_url(shout, cfg_get_stream_url()) != SHOUTERR_SUCCESS) { SHOUTERR_SUCCESS !=
log_error("shout_set_url: %s", shout_set_url(shout, cfg_get_stream_url())) {
shout_get_error(shout)); log_error("shout_set_url: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
} }
if (cfg_get_stream_genre() && if (cfg_get_stream_genre() &&
shout_set_genre(shout, cfg_get_stream_genre()) != SHOUTERR_SUCCESS) { SHOUTERR_SUCCESS !=
log_error("shout_set_genre: %s", shout_set_genre(shout, cfg_get_stream_genre())) {
shout_get_error(shout)); log_error("shout_set_genre: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
} }
if (cfg_get_stream_description() && if (cfg_get_stream_description() &&
shout_set_description(shout, cfg_get_stream_description()) != SHOUTERR_SUCCESS) { SHOUTERR_SUCCESS !=
shout_set_description(shout, cfg_get_stream_description())) {
log_error("shout_set_description: %s", log_error("shout_set_description: %s",
shout_get_error(shout)); shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
}
if (cfg_get_stream_bitrate() &&
shout_set_audio_info(shout, SHOUT_AI_BITRATE, cfg_get_stream_bitrate()) != SHOUTERR_SUCCESS) {
log_error("shout_set_audio_info(AI_BITRATE): %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (cfg_get_stream_channels() &&
shout_set_audio_info(shout, SHOUT_AI_CHANNELS, cfg_get_stream_channels()) != SHOUTERR_SUCCESS) {
log_error("shout_set_audio_info(AI_CHANNELS): %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (cfg_get_stream_samplerate() &&
shout_set_audio_info(shout, SHOUT_AI_SAMPLERATE, cfg_get_stream_samplerate()) != SHOUTERR_SUCCESS) {
log_error("shout_set_audio_info(AI_SAMPLERATE): %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
} }
if (cfg_get_stream_quality() && if (cfg_get_stream_quality() &&
shout_set_audio_info(shout, SHOUT_AI_QUALITY, cfg_get_stream_quality()) != SHOUTERR_SUCCESS) { SHOUTERR_SUCCESS !=
log_error("shout_set_audio_info(AI_QUALITY): %s", shout_set_audio_info(shout, SHOUT_AI_QUALITY,
cfg_get_stream_quality())) {
log_error("shout_set_audio_info: QUALITY: %s",
shout_get_error(shout)); shout_get_error(shout));
shout_free(shout); goto error;
return (NULL); }
if (cfg_get_stream_bitrate() &&
SHOUTERR_SUCCESS !=
shout_set_audio_info(shout, SHOUT_AI_BITRATE,
cfg_get_stream_bitrate())) {
log_error("shout_set_audio_info: BITRATE: %s",
shout_get_error(shout));
goto error;
}
if (cfg_get_stream_samplerate() &&
SHOUTERR_SUCCESS !=
shout_set_audio_info(shout, SHOUT_AI_SAMPLERATE,
cfg_get_stream_samplerate())) {
log_error("shout_set_audio_info: SAMPLERATE: %s",
shout_get_error(shout));
goto error;
}
if (cfg_get_stream_channels() &&
SHOUTERR_SUCCESS !=
shout_set_audio_info(shout, SHOUT_AI_CHANNELS,
cfg_get_stream_channels())) {
log_error("shout_set_audio_info: CHANNELS: %s",
shout_get_error(shout));
goto error;
} }
if (shout_set_public(shout, (unsigned int)cfg_get_stream_server_public()) != SHOUTERR_SUCCESS) { if (SHOUTERR_SUCCESS !=
log_error("shout_set_public: %s", shout_set_public(shout, (unsigned int)cfg_get_stream_server_public())) {
shout_get_error(shout)); log_error("shout_set_public: %s", shout_get_error(shout));
shout_free(shout); goto error;
return (NULL);
} }
return (shout); return (shout);
error:
shout_free(shout);
return (NULL);
} }
char * char *

View File

@ -24,7 +24,7 @@
int strrcmp(const char *, const char *); int strrcmp(const char *, const char *);
int strrcasecmp(const char *, const char *); int strrcasecmp(const char *, const char *);
shout_t * stream_setup(const char *, unsigned short, const char *); shout_t * stream_setup(void);
char * CHARtoUTF8(const char *, int); char * CHARtoUTF8(const char *, int);
char * UTF8toCHAR(const char *, int); char * UTF8toCHAR(const char *, int);