mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2024-11-03 04:17:18 -05:00
Make main() smaller by moving the libshout setup into a separate function.
git-svn-id: https://svn.xiph.org/trunk/ezstream@13586 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
parent
79dc5a37da
commit
8acd8622d0
114
src/ezstream.c
114
src/ezstream.c
@ -1177,120 +1177,8 @@ main(int argc, char *argv[])
|
||||
|
||||
xfree(configFile);
|
||||
|
||||
if ((shout = shout_new()) == NULL) {
|
||||
printf("%s: shout_new(): %s", __progname, strerror(ENOMEM));
|
||||
if ((shout = stream_setup(host, port, mount)) == NULL)
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
|
||||
if (shout_set_host(shout, host) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_host(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_protocol(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
if (shout_set_port(shout, port) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_port: %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
if (shout_set_password(shout, pezConfig->password) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_password(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
if (shout_set_mount(shout, mount) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_mount(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_user(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
|
||||
if (!strcmp(pezConfig->format, MP3_FORMAT)) {
|
||||
if (shout_set_format(shout, SHOUT_FORMAT_MP3) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_format(MP3): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (!strcmp(pezConfig->format, VORBIS_FORMAT) ||
|
||||
!strcmp(pezConfig->format, THEORA_FORMAT)) {
|
||||
if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_format(OGG): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
|
||||
if (pezConfig->serverName) {
|
||||
if (shout_set_name(shout, pezConfig->serverName) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_name(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (pezConfig->serverURL) {
|
||||
if (shout_set_url(shout, pezConfig->serverURL) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_url(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (pezConfig->serverGenre) {
|
||||
if (shout_set_genre(shout, pezConfig->serverGenre) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_genre(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (pezConfig->serverDescription) {
|
||||
if (shout_set_description(shout, pezConfig->serverDescription) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_description(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (pezConfig->serverBitrate) {
|
||||
if (shout_set_audio_info(shout, SHOUT_AI_BITRATE, pezConfig->serverBitrate) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_BITRATE): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (pezConfig->serverChannels) {
|
||||
if (shout_set_audio_info(shout, SHOUT_AI_CHANNELS, pezConfig->serverChannels) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_CHANNELS): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (pezConfig->serverSamplerate) {
|
||||
if (shout_set_audio_info(shout, SHOUT_AI_SAMPLERATE, pezConfig->serverSamplerate) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_SAMPLERATE): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
if (pezConfig->serverQuality) {
|
||||
if (shout_set_audio_info(shout, SHOUT_AI_QUALITY, pezConfig->serverQuality) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_QUALITY): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
}
|
||||
|
||||
if (shout_set_public(shout, pezConfig->serverPublic) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_public(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
return (ez_shutdown(1));
|
||||
}
|
||||
|
||||
if (pezConfig->metadataProgram != NULL)
|
||||
metadataFromProgram = 1;
|
||||
|
141
src/util.c
141
src/util.c
@ -17,6 +17,11 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains utility functions, as well as a few other unexciting
|
||||
* but verbose functions outsourced from ezstream.c to make it more readable.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
@ -25,9 +30,15 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <shout/shout.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "configfile.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
extern EZCONFIG *pezConfig;
|
||||
extern char *__progname;
|
||||
|
||||
int
|
||||
strrcmp(const char *s, const char *sub)
|
||||
{
|
||||
@ -61,3 +72,133 @@ strrcasecmp(const char *s, const char *sub)
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
shout_t *
|
||||
stream_setup(const char *host, const int port, const char *mount)
|
||||
{
|
||||
shout_t *shout = NULL;
|
||||
|
||||
if ((shout = shout_new()) == NULL) {
|
||||
printf("%s: shout_new(): %s", __progname, strerror(ENOMEM));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (shout_set_host(shout, host) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_host(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_protocol(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (shout_set_port(shout, port) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_port: %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (shout_set_password(shout, pezConfig->password) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_password(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (shout_set_mount(shout, mount) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_mount(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_user(): %s\n", __progname,
|
||||
shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (!strcmp(pezConfig->format, MP3_FORMAT) &&
|
||||
shout_set_format(shout, SHOUT_FORMAT_MP3) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_format(MP3): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if ((!strcmp(pezConfig->format, VORBIS_FORMAT) ||
|
||||
!strcmp(pezConfig->format, THEORA_FORMAT)) &&
|
||||
shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_format(OGG): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (pezConfig->serverName &&
|
||||
shout_set_name(shout, pezConfig->serverName) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_name(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (pezConfig->serverURL &&
|
||||
shout_set_url(shout, pezConfig->serverURL) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_url(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (pezConfig->serverGenre &&
|
||||
shout_set_genre(shout, pezConfig->serverGenre) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_genre(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (pezConfig->serverDescription &&
|
||||
shout_set_description(shout, pezConfig->serverDescription) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_description(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (pezConfig->serverBitrate &&
|
||||
shout_set_audio_info(shout, SHOUT_AI_BITRATE, pezConfig->serverBitrate) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_BITRATE): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (pezConfig->serverChannels &&
|
||||
shout_set_audio_info(shout, SHOUT_AI_CHANNELS, pezConfig->serverChannels) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_CHANNELS): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (pezConfig->serverSamplerate &&
|
||||
shout_set_audio_info(shout, SHOUT_AI_SAMPLERATE, pezConfig->serverSamplerate) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_SAMPLERATE): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
if (pezConfig->serverQuality &&
|
||||
shout_set_audio_info(shout, SHOUT_AI_QUALITY, pezConfig->serverQuality) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_audio_info(AI_QUALITY): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (shout_set_public(shout, pezConfig->serverPublic) != SHOUTERR_SUCCESS) {
|
||||
printf("%s: shout_set_public(): %s\n",
|
||||
__progname, shout_get_error(shout));
|
||||
shout_free(shout);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (shout);
|
||||
}
|
||||
|
@ -22,5 +22,6 @@
|
||||
|
||||
int strrcmp(const char *, const char *);
|
||||
int strrcasecmp(const char *, const char *);
|
||||
shout_t * stream_setup(const char *, const int, const char *);
|
||||
|
||||
#endif /* __UTIL_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user