[xiph-commits] r13586 - trunk/ezstream/src
moritz at svn.xiph.org
moritz at svn.xiph.org
Wed Aug 22 08:15:50 PDT 2007
Author: moritz
Date: 2007-08-22 08:15:49 -0700 (Wed, 22 Aug 2007)
New Revision: 13586
Modified:
trunk/ezstream/src/ezstream.c
trunk/ezstream/src/util.c
trunk/ezstream/src/util.h
Log:
Make main() smaller by moving the libshout setup into a separate function.
Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c 2007-08-22 13:32:07 UTC (rev 13585)
+++ trunk/ezstream/src/ezstream.c 2007-08-22 15:15:49 UTC (rev 13586)
@@ -1177,121 +1177,9 @@
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;
else
Modified: trunk/ezstream/src/util.c
===================================================================
--- trunk/ezstream/src/util.c 2007-08-22 13:32:07 UTC (rev 13585)
+++ trunk/ezstream/src/util.c 2007-08-22 15:15:49 UTC (rev 13586)
@@ -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)
{
@@ -43,10 +54,10 @@
int
strrcasecmp(const char *s, const char *sub)
{
- char *s_cpy = xstrdup(s);
- char *sub_cpy = xstrdup(sub);
- char *p;
- int ret;
+ char *s_cpy = xstrdup(s);
+ char *sub_cpy = xstrdup(sub);
+ char *p;
+ int ret;
for (p = s_cpy; *p != '\0'; p++)
*p = tolower((int)*p);
@@ -61,3 +72,133 @@
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);
+}
Modified: trunk/ezstream/src/util.h
===================================================================
--- trunk/ezstream/src/util.h 2007-08-22 13:32:07 UTC (rev 13585)
+++ trunk/ezstream/src/util.h 2007-08-22 15:15:49 UTC (rev 13586)
@@ -20,7 +20,8 @@
#ifndef __UTIL_H__
#define __UTIL_H__
-int strrcmp(const char *, const char *);
-int strrcasecmp(const char *, const char *);
+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__ */
More information about the commits
mailing list