source: roaraudio/roarclients/roarctl.c @ 25:0e8582e163ea

Last change on this file since 25:0e8582e163ea was 25:0e8582e163ea, checked in by phi, 16 years ago

added code to use roar_get_vol()

File size: 6.9 KB
Line 
1//roarctl.c:
2
3#include <roaraudio.h>
4
5int display_mixer (struct roar_connection * con, int stream);
6
7void usage (void) {
8 printf("roarcat [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
9
10 printf("\nOptions:\n\n");
11
12 printf("  --server SERVER    - Set server hostname\n"
13        "  --help             - Show this help\n"
14       );
15
16 printf("\nCommands:\n\n");
17 printf(
18        "  help               - Show this help\n"
19        "\n"
20        "  standby, off       - Go into standby mode\n"
21        "  resume, on         - Go into active mode\n"
22        "  standbymode        - Show current standby mode\n"
23        "  exit               - Quits the roard (must be used as last command)\n"
24        "\n"
25        "  kick TYPE ID       - Kicks object of TYPE with id ID\n"
26        "                       Types: client stream sample source\n"
27        "\n"
28        "  serveroinfo        - Gets Informations about server output\n"
29        "  listclients        - Gets Informations about clients\n"
30        "  liststreams        - Gets Informations about streams\n"
31        "  allinfo            - Get all infos\n"
32       );
33}
34
35void server_oinfo (struct roar_connection * con) {
36 struct roar_stream s;
37
38 if ( roar_server_oinfo(con, &s) == -1 ) {
39  fprintf(stderr, "Error: can not get server output info\n");
40  return;
41 }
42
43 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
44 printf("Server Output rate    : %i\n", s.info.rate);
45 printf("Server Output bits    : %i\n", s.info.bits);
46 printf("Server Output channels: %i\n", s.info.channels);
47 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
48                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
49// printf("Server Output rate: %i", s.info.rate);
50}
51
52void list_clients (struct roar_connection * con) {
53 int i;
54 int num;
55 int h;
56 int id[ROAR_CLIENTS_MAX];
57 struct roar_client c;
58
59 if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) {
60  fprintf(stderr, "Error: can not get client list\n");
61  return;
62 }
63
64 for (i = 0; i < num; i++) {
65  printf("client %i:\n", id[i]);
66  if ( roar_get_client(con, &c, id[i]) == -1 ) {
67   fprintf(stderr, "Error: can not get client info\n");
68   continue;
69  }
70  printf("Player name           : %s\n", c.name);
71  if ( c.execed != -1 )
72   printf("Execed stream         : %i\n", c.execed);
73
74  for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++)
75   if ( c.streams[h] != -1 )
76    printf("stream                : %i\n", c.streams[h]);
77 }
78
79}
80
81void list_streams (struct roar_connection * con) {
82 int i;
83 int num;
84 int id[ROAR_STREAMS_MAX];
85 struct roar_stream s;
86
87
88 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
89  fprintf(stderr, "Error: can not get stream list\n");
90  return;
91 }
92
93 for (i = 0; i < num; i++) {
94  printf("stream %i:\n", id[i]);
95  if ( roar_get_stream(con, &s, id[i]) == -1 ) {
96   fprintf(stderr, "Error: can not get stream info\n");
97   continue;
98  }
99  printf("Stream direction      : %s\n", roar_dir2str(s.dir));
100  if ( s.pos_rel_id == -1 )
101   printf("Relativ position id   : none (stream not synchronized)\n");
102  else
103   printf("Relativ position id   : %i\n", s.pos_rel_id);
104  printf("Input rate            : %i\n", s.info.rate);
105  printf("Input bits            : %i\n", s.info.bits);
106  printf("Input channels        : %i\n", s.info.channels);
107  printf("Input codec           : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
108                                      s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
109  display_mixer(con, id[i]);
110 }
111
112}
113
114int display_mixer (struct roar_connection * con, int stream) {
115 int channels;
116 struct roar_mixer_settings mixer;
117 int i;
118
119 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
120  fprintf(stderr, "Error: can not get stream mixer info\n");
121  return -1;
122 }
123
124 for (i = 0; i < channels; i++)
125  printf("Mixer volume chan %2i  : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35);
126
127 return 0;
128}
129
130int main (int argc, char * argv[]) {
131 struct roar_connection con;
132 char * server   = NULL;
133 char * k = NULL;
134 int    i;
135 int    t = 0;
136
137 for (i = 1; i < argc; i++) {
138  k = argv[i];
139
140  if ( strcmp(k, "--server") == 0 ) {
141   server = k;
142  } else if ( strcmp(k, "--help") == 0 ) {
143   usage();
144   return 0;
145  } else if ( *k == '-' ) {
146   fprintf(stderr, "Error: unknown argument: %s\n", k);
147   usage();
148   return 1;
149  } else {
150   break;
151  }
152 }
153
154 // connect
155
156 if ( roar_connect(&con, server) == -1 ) {
157  fprintf(stderr, "Error: Can not connect to server\n");
158  return 1;
159 }
160
161 if ( roar_identify(&con, "roarctl") == -1 ) {
162  fprintf(stderr, "Error: Can not identify to server\n");
163  return 1;
164 }
165
166 if ( i == argc ) {
167  fprintf(stderr, "Error: No Commands given\n");
168  return 0; // this is not a fatal error...
169 }
170
171 for (; i < argc; i++) {
172  k = argv[i];
173  // cmd is in k
174
175  printf("--- [ %s ] ---\n", k);
176
177  if ( !strcmp(k, "help") ) {
178   usage();
179
180
181  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
182   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
183    fprintf(stderr, "Error: can not set mode to standby\n");
184   } else {
185    printf("going into standby\n");
186   }
187  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
188   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
189    fprintf(stderr, "Error: can not set mode to active\n");
190   } else {
191    printf("going into active mode\n");
192   }
193
194  } else if ( !strcmp(k, "exit") ) {
195   if ( roar_exit(&con) == -1 ) {
196    fprintf(stderr, "Error: can not quit server\n");
197   } else {
198    printf("Server quited\n");
199    break;
200   }
201
202  } else if ( !strcmp(k, "standbymode") ) {
203   t = roar_get_standby(&con);
204   if ( t == -1 ) {
205    fprintf(stderr, "Error: can not get stanby mode\n");
206   } else if ( t == ROAR_STANDBY_ACTIVE ) {
207    printf("Server is in standby\n");
208   } else if ( t == ROAR_STANDBY_INACTIVE ) {
209    printf("Server is active\n");
210   } else {
211    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
212   }
213
214  } else if ( !strcmp(k, "serveroinfo") ) {
215   server_oinfo(&con);
216  } else if ( !strcmp(k, "listclients") ) {
217   list_clients(&con);
218  } else if ( !strcmp(k, "liststreams") ) {
219   list_streams(&con);
220  } else if ( !strcmp(k, "allinfo") ) {
221   server_oinfo(&con);
222   printf("\n");
223   list_clients(&con);
224   printf("\n");
225   list_streams(&con);
226
227  } else if ( !strcmp(k, "kick") ) {
228   k = argv[++i];
229   if ( !strcmp(k, "client") ) {
230    t = ROAR_OT_CLIENT;
231   } else if ( !strcmp(k, "stream") ) {
232    t = ROAR_OT_STREAM;
233   } else if ( !strcmp(k, "sample") ) {
234    t = ROAR_OT_SAMPLE;
235   } else if ( !strcmp(k, "source") ) {
236    t = ROAR_OT_SOURCE;
237   } else {
238    fprintf(stderr, "Error: unknown type: %s\n", k);
239    continue;
240   }
241   //t = atoi(argv[i++]);
242   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
243    fprintf(stderr, "Error: can not kick %s\n", k);
244   } else {
245    printf("%s kicked\n", k);
246   }
247
248  } else {
249   fprintf(stderr, "Error: invalid command: %s\n", k);
250  }
251
252 }
253
254 roar_disconnect(&con);
255
256 return 0;
257}
258
259//ll
Note: See TracBrowser for help on using the repository browser.