source: roaraudio/roarclients/roarshout.c @ 2292:0e4ee5724202

Last change on this file since 2292:0e4ee5724202 was 2292:0e4ee5724202, checked in by phi, 15 years ago

simple patches, mostly by Simon Matter (trivial by german law so no (c) notice)

File size: 5.5 KB
Line 
1//roarshout.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26
27#ifdef ROAR_HAVE_LIBSHOUT
28#include <shout/shout.h>
29
30#define BUFSIZE 2048
31
32void usage (void) {
33 printf("roarshout [OPTIONS]... [address [port [password [mountpoint]]]\n");
34
35 printf("\nRoarAudio Options:\n\n");
36
37 printf("    --server SERVER    - Set server hostname\n"
38        "    --rate   RATE      - Set sample rate\n"
39        "    --bits   BITS      - Set bits per sample\n"
40        "    --chans  CHANNELS  - Set number of channels\n"
41        "    --codec  CODEC     - Set the codec\n"
42        " -h --help             - Show this help\n"
43       );
44
45 printf("\nlibshout Options:\n\n");
46
47 printf(" -p --public           - Allow listing in stream directory\n"
48        " -d          DESC      - Set stream description\n"
49        " -g          GENRE     - Set stream genre\n"
50        " -n          NAME      - Set stream name\n"
51        " -u          URL       - Set stream URL/homepage\n"
52       );
53
54}
55
56int main (int argc, char * argv[]) {
57 int    rate     = 44100;
58 int    bits     = 16;
59 int    channels = 2;
60 int    codec    = ROAR_CODEC_OGG_VORBIS;
61 char * server   = NULL;
62 char * k;
63 char * s_server = NULL;
64 char * s_mount  = NULL;
65 char * s_pw     = NULL;
66 int    s_port   = -1;
67 char * s_desc   = NULL;
68 char * s_genre  = NULL;
69 char * s_name   = NULL;
70 char * s_url    = NULL;
71 int    s_public = 0;
72 int    fh;
73 int    i;
74 char buf[BUFSIZE];
75 shout_t * shout;
76
77 for (i = 1; i < argc; i++) {
78  k = argv[i];
79
80  if ( strcmp(k, "--server") == 0 ) {
81   server = argv[++i];
82  } else if ( strcmp(k, "--rate") == 0 ) {
83   rate = atoi(argv[++i]);
84  } else if ( strcmp(k, "--bits") == 0 ) {
85   bits = atoi(argv[++i]);
86  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) {
87   channels = atoi(argv[++i]);
88  } else if ( strcmp(k, "--codec") == 0 ) {
89   codec = roar_str2codec(argv[++i]);
90  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--public") == 0 ) {
91   s_public = 1;
92  } else if ( strcmp(k, "-d") == 0 ) {
93   s_desc   = argv[++i];
94  } else if ( strcmp(k, "-g") == 0 ) {
95   s_genre  = argv[++i];
96  } else if ( strcmp(k, "-n") == 0 ) {
97   s_name   = argv[++i];
98  } else if ( strcmp(k, "-u") == 0 ) {
99   s_url    = argv[++i];
100  } else if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
101   usage();
102   return 0;
103  } else if ( s_server == NULL ) {
104   s_server = k;
105  } else if ( s_port   == -1 ) {
106   s_port   = atoi(k);
107  } else if ( s_pw     == NULL ) {
108   s_pw     = k;
109  } else if ( s_mount  == NULL ) {
110   s_mount  = k;
111  } else {
112   fprintf(stderr, "Error: unknown argument: %s\n", k);
113   usage();
114   return 1;
115  }
116 }
117
118 if ( s_server == NULL )
119  s_server = "localhost";
120
121 if ( s_mount == NULL )
122  s_mount  = "/roar.ogg";
123
124 if ( s_pw == NULL )
125  s_pw     = "hackme";
126
127 if ( s_port == -1 )
128  s_port   = 8000;
129
130 shout_init();
131
132 if (!(shout = shout_new())) {
133  ROAR_ERR("Can not clreate shout object");
134  return 1;
135 }
136
137 if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) {
138  ROAR_ERR("Error setting hostname: %s", shout_get_error(shout));
139  return 1;
140 }
141
142 if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
143  ROAR_ERR("Error setting protocol: %s", shout_get_error(shout));
144  return 1;
145 }
146
147 if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) {
148  ROAR_ERR("Error setting port: %s", shout_get_error(shout));
149  return 1;
150 }
151
152 if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) {
153  ROAR_ERR("Error setting password: %s", shout_get_error(shout));
154  return 1;
155 }
156
157 if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) {
158  ROAR_ERR("Error setting mount: %s", shout_get_error(shout));
159  return 1;
160 }
161
162 if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
163  ROAR_ERR("Error setting user: %s", shout_get_error(shout));
164  return 1;
165 }
166
167 if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
168  ROAR_ERR("Error setting format: %s", shout_get_error(shout));
169  return 1;
170 }
171
172 shout_set_public(shout, s_public);
173
174 if (s_desc  != NULL)
175  shout_set_description(shout, s_desc);
176
177 if (s_genre != NULL)
178  shout_set_genre(shout, s_genre);
179
180 if (s_name  != NULL)
181  shout_set_name(shout, s_name);
182
183 if (s_url   != NULL)
184  shout_set_url(shout, s_url);
185
186 if ( (fh = roar_simple_monitor(rate, channels, bits, codec, server, "roarshout")) == -1 ) {
187  fprintf(stderr, "Error: can not start monetoring\n");
188  return 1;
189 }
190
191 if (shout_open(shout) != SHOUTERR_SUCCESS) {
192  ROAR_ERR("Can not open connection via libshout!");
193  return -1;
194 }
195
196 while((i = read(fh, buf, BUFSIZE)))
197  if (shout_send(shout, (unsigned char*)buf, i) != SHOUTERR_SUCCESS)
198   break;
199
200 roar_simple_close(fh);
201
202 shout_sync(shout);
203
204 shout_close(shout);
205
206 shout_shutdown();
207
208 return 0;
209}
210
211#else
212int main (void) {
213 fprintf(stderr, "No libshout support compiled in!\n");
214 return 1;
215}
216#endif
217//ll
Note: See TracBrowser for help on using the repository browser.