source: roaraudio/roarclients/roarshout.c @ 907:127879cb2855

Last change on this file since 907:127879cb2855 was 907:127879cb2855, checked in by phi, 15 years ago

added oggfwd like command lion for shout server/port/pw/mount

File size: 4.3 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("roarmon [OPTIONS]...\n");
34
35 printf("\nOptions:\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        "  --help             - Show this help\n"
43       );
44
45}
46
47int main (int argc, char * argv[]) {
48 int    rate     = 44100;
49 int    bits     = 16;
50 int    channels = 2;
51 int    codec    = ROAR_CODEC_OGG_VORBIS;
52 char * server   = NULL;
53 char * k;
54 char * s_server = NULL;
55 char * s_mount  = NULL;
56 char * s_pw     = NULL;
57 int    s_port   = -1;
58 int    fh;
59 int    i;
60 char buf[BUFSIZE];
61 shout_t * shout;
62
63 for (i = 1; i < argc; i++) {
64  k = argv[i];
65
66  if ( strcmp(k, "--server") == 0 ) {
67   server = argv[++i];
68  } else if ( strcmp(k, "--rate") == 0 ) {
69   rate = atoi(argv[++i]);
70  } else if ( strcmp(k, "--bits") == 0 ) {
71   bits = atoi(argv[++i]);
72  } else if ( strcmp(k, "--channels") == 0 ) {
73   channels = atoi(argv[++i]);
74  } else if ( strcmp(k, "--codec") == 0 ) {
75   codec = roar_str2codec(argv[++i]);
76  } else if ( strcmp(k, "--help") == 0 ) {
77   usage();
78   return 0;
79  } else if ( s_server == NULL ) {
80   s_server = k;
81  } else if ( s_port   == -1 ) {
82   s_port   = atoi(k);
83  } else if ( s_pw     == NULL ) {
84   s_pw     = k;
85  } else if ( s_mount  == NULL ) {
86   s_mount  = k;
87  } else {
88   fprintf(stderr, "Error: unknown argument: %s\n", k);
89   usage();
90   return 1;
91  }
92 }
93
94 if ( s_server == NULL )
95  s_server = "localhost";
96
97 if ( s_mount == NULL )
98  s_mount  = "/roar.ogg";
99
100 if ( s_pw == NULL )
101  s_pw     = "hackme";
102
103 if ( s_port == -1 )
104  s_port   = 8000;
105
106 shout_init();
107
108 if (!(shout = shout_new())) {
109  ROAR_ERR("Can not clreate shout object");
110  return 1;
111 }
112
113 if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) {
114  ROAR_ERR("Error setting hostname: %s", shout_get_error(shout));
115  return 1;
116 }
117
118 if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
119  ROAR_ERR("Error setting protocol: %s", shout_get_error(shout));
120  return 1;
121 }
122
123 if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) {
124  ROAR_ERR("Error setting port: %s", shout_get_error(shout));
125  return 1;
126 }
127
128 if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) {
129  ROAR_ERR("Error setting password: %s", shout_get_error(shout));
130  return 1;
131 }
132
133 if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) {
134  ROAR_ERR("Error setting mount: %s", shout_get_error(shout));
135  return 1;
136 }
137
138 if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
139  ROAR_ERR("Error setting user: %s", shout_get_error(shout));
140  return 1;
141 }
142
143 if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
144  ROAR_ERR("Error setting format: %s", shout_get_error(shout));
145  return 1;
146 }
147
148 if ( (fh = roar_simple_monitor(rate, channels, bits, codec, server, "roarshout")) == -1 ) {
149  fprintf(stderr, "Error: can not start monetoring\n");
150  return 1;
151 }
152
153 if (shout_open(shout) != SHOUTERR_SUCCESS) {
154  ROAR_ERR("Can not open connection via libshout!");
155  return -1;
156 }
157
158 while((i = read(fh, buf, BUFSIZE)))
159  if (shout_send(shout, buf, i) != SHOUTERR_SUCCESS)
160   break;
161
162 roar_simple_close(fh);
163
164 shout_sync(shout);
165
166 shout_close(shout);
167
168 shout_shutdown();
169
170 return 0;
171}
172
173#else
174int main (void) {
175 fprintf(stderr, "No libshout support compiled in!\n");
176 return 1;
177}
178#endif
179//ll
Note: See TracBrowser for help on using the repository browser.