source: roaraudio/roarclients/roarshout.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27
28#ifdef ROAR_HAVE_LIBSHOUT
29#include <shout/shout.h>
30
31#define BUFSIZE 2048
32
33void usage (void) {
34 printf("roarshout [OPTIONS]... [address [port [password [mountpoint]]]\n");
35
36 printf("\nRoarAudio Options:\n\n");
37
38 printf("    --server SERVER    - Set server hostname\n"
39        "    --rate   RATE      - Set sample rate\n"
40        "    --bits   BITS      - Set bits per sample\n"
41        "    --chans  CHANNELS  - Set number of channels\n"
42        "    --codec  CODEC     - Set the codec\n"
43        " -h --help             - Show this help\n"
44       );
45
46 printf("\nlibshout Options:\n\n");
47
48 printf(" -p --public           - Allow listing in stream directory\n"
49        " -d          DESC      - Set stream description\n"
50        " -g          GENRE     - Set stream genre\n"
51        " -n          NAME      - Set stream name\n"
52        " -u          URL       - Set stream URL/homepage\n"
53       );
54
55}
56
57int main (int argc, char * argv[]) {
58 int    rate     = 44100;
59 int    bits     = 16;
60 int    channels = 2;
61 int    codec    = ROAR_CODEC_OGG_VORBIS;
62 char * server   = NULL;
63 char * k;
64 char * s_server = NULL;
65 char * s_mount  = NULL;
66 char * s_pw     = NULL;
67 int    s_port   = -1;
68 char * s_desc   = NULL;
69 char * s_genre  = NULL;
70 char * s_name   = NULL;
71 char * s_url    = NULL;
72 int    s_public = 0;
73 int    fh;
74 int    i;
75 char buf[BUFSIZE];
76 shout_t * shout;
77
78 for (i = 1; i < argc; i++) {
79  k = argv[i];
80
81  if ( strcmp(k, "--server") == 0 ) {
82   server = argv[++i];
83  } else if ( strcmp(k, "--rate") == 0 ) {
84   rate = atoi(argv[++i]);
85  } else if ( strcmp(k, "--bits") == 0 ) {
86   bits = atoi(argv[++i]);
87  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) {
88   channels = atoi(argv[++i]);
89  } else if ( strcmp(k, "--codec") == 0 ) {
90   codec = roar_str2codec(argv[++i]);
91  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--public") == 0 ) {
92   s_public = 1;
93  } else if ( strcmp(k, "-d") == 0 ) {
94   s_desc   = argv[++i];
95  } else if ( strcmp(k, "-g") == 0 ) {
96   s_genre  = argv[++i];
97  } else if ( strcmp(k, "-n") == 0 ) {
98   s_name   = argv[++i];
99  } else if ( strcmp(k, "-u") == 0 ) {
100   s_url    = argv[++i];
101  } else if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
102   usage();
103   return 0;
104  } else if ( s_server == NULL ) {
105   s_server = k;
106  } else if ( s_port   == -1 ) {
107   s_port   = atoi(k);
108  } else if ( s_pw     == NULL ) {
109   s_pw     = k;
110  } else if ( s_mount  == NULL ) {
111   s_mount  = k;
112  } else {
113   fprintf(stderr, "Error: unknown argument: %s\n", k);
114   usage();
115   return 1;
116  }
117 }
118
119 if ( s_server == NULL )
120  s_server = "localhost";
121
122 if ( s_mount == NULL )
123  s_mount  = "/roar.ogg";
124
125 if ( s_pw == NULL )
126  s_pw     = "hackme";
127
128 if ( s_port == -1 )
129  s_port   = 8000;
130
131 shout_init();
132
133 if (!(shout = shout_new())) {
134  ROAR_ERR("Can not create shout object");
135  return 1;
136 }
137
138 if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) {
139  ROAR_ERR("Error setting hostname: %s", shout_get_error(shout));
140  return 1;
141 }
142
143 if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
144  ROAR_ERR("Error setting protocol: %s", shout_get_error(shout));
145  return 1;
146 }
147
148 if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) {
149  ROAR_ERR("Error setting port: %s", shout_get_error(shout));
150  return 1;
151 }
152
153 if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) {
154  ROAR_ERR("Error setting password: %s", shout_get_error(shout));
155  return 1;
156 }
157
158 if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) {
159  ROAR_ERR("Error setting mount: %s", shout_get_error(shout));
160  return 1;
161 }
162
163 if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
164  ROAR_ERR("Error setting user: %s", shout_get_error(shout));
165  return 1;
166 }
167
168 if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
169  ROAR_ERR("Error setting format: %s", shout_get_error(shout));
170  return 1;
171 }
172
173 shout_set_public(shout, s_public);
174
175 if (s_desc  != NULL)
176  shout_set_description(shout, s_desc);
177
178 if (s_genre != NULL)
179  shout_set_genre(shout, s_genre);
180
181 if (s_name  != NULL)
182  shout_set_name(shout, s_name);
183
184 if (s_url   != NULL)
185  shout_set_url(shout, s_url);
186
187 if ( (fh = roar_simple_monitor(rate, channels, bits, codec, server, "roarshout")) == -1 ) {
188  fprintf(stderr, "Error: can not start monitoring\n");
189  return 1;
190 }
191
192 if (shout_open(shout) != SHOUTERR_SUCCESS) {
193  ROAR_ERR("Can not open connection via libshout!");
194  return -1;
195 }
196
197 while((i = read(fh, buf, BUFSIZE)))
198  if (shout_send(shout, (unsigned char*)buf, i) != SHOUTERR_SUCCESS)
199   break;
200
201 roar_simple_close(fh);
202
203 shout_sync(shout);
204
205 shout_close(shout);
206
207 shout_shutdown();
208
209 return 0;
210}
211
212#else
213int main (void) {
214 fprintf(stderr, "No libshout support compiled in!\n");
215 return 1;
216}
217#endif
218//ll
Note: See TracBrowser for help on using the repository browser.