source: roaraudio/roarclients/roarshout.c @ 605:f1450dcc5dc5

Last change on this file since 605:f1450dcc5dc5 was 605:f1450dcc5dc5, checked in by phi, 16 years ago

added a lot basic code to roarshout

File size: 3.1 KB
Line 
1//roarshout.c:
2
3#include <roaraudio.h>
4
5#ifdef ROAR_HAVE_LIBSHOUT
6#include <shout/shout.h>
7
8#define BUFSIZE 2048
9
10void usage (void) {
11 printf("roarmon [OPTIONS]...\n");
12
13 printf("\nOptions:\n\n");
14
15 printf("  --server SERVER    - Set server hostname\n"
16        "  --rate   RATE      - Set sample rate\n"
17        "  --bits   BITS      - Set bits per sample\n"
18        "  --chans  CHANNELS  - Set number of channels\n"
19        "  --codec  CODEC     - Set the codec\n"
20        "  --help             - Show this help\n"
21       );
22
23}
24
25int main (int argc, char * argv[]) {
26 int    rate     = 44100;
27 int    bits     = 16;
28 int    channels = 2;
29 int    codec    = ROAR_CODEC_OGG_VORBIS;
30 char * server   = NULL;
31 char * k;
32 char * s_server = "localhost";
33 char * s_mount  = "/roar.ogg";
34 char * s_pw     = "hackme";
35 int    s_port   = 8000;
36 int    fh;
37 int    i;
38 char buf[BUFSIZE];
39 shout_t * shout;
40
41 for (i = 1; i < argc; i++) {
42  k = argv[i];
43
44  if ( strcmp(k, "--server") == 0 ) {
45   server = argv[++i];
46  } else if ( strcmp(k, "--rate") == 0 ) {
47   rate = atoi(argv[++i]);
48  } else if ( strcmp(k, "--bits") == 0 ) {
49   bits = atoi(argv[++i]);
50  } else if ( strcmp(k, "--channels") == 0 ) {
51   channels = atoi(argv[++i]);
52  } else if ( strcmp(k, "--codec") == 0 ) {
53   codec = roar_str2codec(argv[++i]);
54  } else if ( strcmp(k, "--help") == 0 ) {
55   usage();
56   return 0;
57  } else {
58   fprintf(stderr, "Error: unknown argument: %s\n", k);
59   usage();
60   return 1;
61  }
62 }
63
64 shout_init();
65
66 if (!(shout = shout_new())) {
67  ROAR_ERR("Can not clreate shout object");
68  return 1;
69 }
70
71 if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) {
72  ROAR_ERR("Error setting hostname: %s", shout_get_error(shout));
73  return 1;
74 }
75
76 if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
77  ROAR_ERR("Error setting protocol: %s", shout_get_error(shout));
78  return 1;
79 }
80
81 if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) {
82  ROAR_ERR("Error setting port: %s", shout_get_error(shout));
83  return 1;
84 }
85
86 if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) {
87  ROAR_ERR("Error setting password: %s", shout_get_error(shout));
88  return 1;
89 }
90
91 if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) {
92  ROAR_ERR("Error setting mount: %s", shout_get_error(shout));
93  return 1;
94 }
95
96 if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
97  ROAR_ERR("Error setting user: %s", shout_get_error(shout));
98  return 1;
99 }
100
101 if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
102  ROAR_ERR("Error setting format: %s", shout_get_error(shout));
103  return 1;
104 }
105
106 if ( (fh = roar_simple_monitor(rate, channels, bits, codec, server, "roarshout")) == -1 ) {
107  fprintf(stderr, "Error: can not start monetoring\n");
108  return 1;
109 }
110
111 if (shout_open(shout) != SHOUTERR_SUCCESS) {
112  ROAR_ERR("Can not open connection via libshout!");
113  return -1;
114 }
115
116 while((i = read(fh, buf, BUFSIZE)))
117  if (shout_send(shout, buf, i) != SHOUTERR_SUCCESS)
118   break;
119
120 roar_simple_close(fh);
121
122 shout_sync(shout);
123
124 shout_close(shout);
125
126 shout_shutdown();
127
128 return 0;
129}
130
131#else
132int main (void) {
133 fprintf(stderr, "No libshout support compiled in!\n");
134 return 1;
135}
136#endif
137//ll
Note: See TracBrowser for help on using the repository browser.