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());
}
shout = stream_setup(cfg_get_server_hostname(),
cfg_get_server_port(), cfg_get_stream_mountpoint());
if (shout == NULL)
if (NULL == (shout = stream_setup()))
return (ez_shutdown(1));
#ifdef HAVE_SIGNALS

View File

@ -82,139 +82,149 @@ strrcasecmp(const char *s, const char *sub)
}
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) {
log_syserr(ERROR, ENOMEM, "shout_new");
return (NULL);
}
if (shout_set_host(shout, host) != SHOUTERR_SUCCESS) {
log_error("shout_set_host: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
switch (cfg_get_server_protocol()) {
case CFG_PROTO_HTTP:
if (SHOUTERR_SUCCESS !=
shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP)) {
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) {
log_error("shout_set_protocol: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
if (SHOUTERR_SUCCESS !=
shout_set_host(shout, cfg_get_server_hostname())) {
log_error("shout_set_host: %s", shout_get_error(shout));
goto error;
}
if (shout_set_port(shout, port) != SHOUTERR_SUCCESS) {
log_error("shout_set_port: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
if (SHOUTERR_SUCCESS !=
shout_set_port(shout, (unsigned short)cfg_get_server_port())) {
log_error("shout_set_port: %s", shout_get_error(shout));
goto error;
}
if (shout_set_password(shout, cfg_get_server_password()) != SHOUTERR_SUCCESS) {
log_error("shout_set_password: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
if (SHOUTERR_SUCCESS !=
shout_set_user(shout, cfg_get_server_user())) {
log_error("shout_set_user: %s", shout_get_error(shout));
goto error;
}
if (shout_set_mount(shout, mount) != SHOUTERR_SUCCESS) {
log_error("shout_set_mount: %s",
shout_get_error(shout));
shout_free(shout);
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 (SHOUTERR_SUCCESS !=
shout_set_password(shout, cfg_get_server_password())) {
log_error("shout_set_password: %s", shout_get_error(shout));
goto error;
}
if (CFG_STREAM_MP3 == cfg_get_stream_format() &&
shout_set_format(shout, SHOUT_FORMAT_MP3) != SHOUTERR_SUCCESS) {
log_error("shout_set_format(MP3): %s",
shout_get_error(shout));
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 (SHOUTERR_SUCCESS !=
shout_set_mount(shout, cfg_get_stream_mountpoint())) {
log_error("shout_set_mount: %s", shout_get_error(shout));
goto error;
}
if (shout_set_user(shout, cfg_get_server_user()) != SHOUTERR_SUCCESS) {
log_error("shout_set_user: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
switch (cfg_get_stream_format()) {
case CFG_STREAM_VORBIS:
case CFG_STREAM_THEORA:
if (SHOUTERR_SUCCESS !=
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() &&
shout_set_name(shout, cfg_get_stream_name()) != SHOUTERR_SUCCESS) {
log_error("shout_set_name: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
SHOUTERR_SUCCESS !=
shout_set_name(shout, cfg_get_stream_name())) {
log_error("shout_set_name: %s", shout_get_error(shout));
goto error;
}
if (cfg_get_stream_url() &&
shout_set_url(shout, cfg_get_stream_url()) != SHOUTERR_SUCCESS) {
log_error("shout_set_url: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
SHOUTERR_SUCCESS !=
shout_set_url(shout, cfg_get_stream_url())) {
log_error("shout_set_url: %s", shout_get_error(shout));
goto error;
}
if (cfg_get_stream_genre() &&
shout_set_genre(shout, cfg_get_stream_genre()) != SHOUTERR_SUCCESS) {
log_error("shout_set_genre: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
SHOUTERR_SUCCESS !=
shout_set_genre(shout, cfg_get_stream_genre())) {
log_error("shout_set_genre: %s", shout_get_error(shout));
goto error;
}
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",
shout_get_error(shout));
shout_free(shout);
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);
goto error;
}
if (cfg_get_stream_quality() &&
shout_set_audio_info(shout, SHOUT_AI_QUALITY, cfg_get_stream_quality()) != SHOUTERR_SUCCESS) {
log_error("shout_set_audio_info(AI_QUALITY): %s",
SHOUTERR_SUCCESS !=
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_free(shout);
return (NULL);
goto error;
}
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) {
log_error("shout_set_public: %s",
shout_get_error(shout));
shout_free(shout);
return (NULL);
if (SHOUTERR_SUCCESS !=
shout_set_public(shout, (unsigned int)cfg_get_stream_server_public())) {
log_error("shout_set_public: %s", shout_get_error(shout));
goto error;
}
return (shout);
error:
shout_free(shout);
return (NULL);
}
char *

View File

@ -24,7 +24,7 @@
int strrcmp(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 * UTF8toCHAR(const char *, int);