source: roaraudio/libroaresd/esdctl.c @ 17:411717cefded

Last change on this file since 17:411717cefded was 17:411717cefded, checked in by phi, 16 years ago

now we can change the volume, but it will not work if you set it... haha...

File size: 6.9 KB
Line 
1//esdctl.c:
2
3#include "libroaresd.h"
4
5/* lock/unlock will disable/enable foreign clients from connecting */
6
7// we do not have such a thing at the moment...
8// so always return -1
9int esd_lock( int esd ) {
10 return -1;
11}
12int esd_unlock( int esd ) {
13 return -1;
14}
15
16/* standby/resume will free/reclaim audio device so others may use it */
17int esd_standby( int esd ) {
18 struct roar_connection con;
19
20 con.fh = esd;
21
22 return roar_set_standby(&con, ROAR_STANDBY_ACTIVE);
23}
24
25int esd_resume( int esd ) {
26 struct roar_connection con;
27
28 con.fh = esd;
29
30 return roar_set_standby(&con, ROAR_STANDBY_INACTIVE);
31}
32
33/* print server into to stdout */
34void esd_print_server_info( esd_server_info_t *server_info ) {
35 char buf[80] = "";
36
37 if ( server_info->format & ESD_BITS8 )
38  strcat(buf, "8 bit ");
39 else
40  strcat(buf, "16 bit ");
41
42 if ( server_info->format & ESD_MONO )
43  strcat(buf, "stereo ");
44 else
45  strcat(buf, "mono ");
46
47 printf("server version   = %i\n",        server_info->version);
48 printf("server format    = 0x%08x %s\n", server_info->format, buf);
49 printf("server rate      = %i\n",        server_info->rate);
50}
51
52
53void esd_print_player_info( esd_player_info_t *player_info ) {
54 char buf[80] = "";
55
56 if ( player_info->format & ESD_BITS8 )
57  strcat(buf, "8 bit ");
58 else
59  strcat(buf, "16 bit ");
60
61 if ( player_info->format & ESD_MONO )
62  strcat(buf, "stereo ");
63 else
64  strcat(buf, "mono ");
65
66 printf("player %i name    = %s\n",        player_info->source_id, player_info->name);
67 printf("player %i format  = 0x%08x %s\n", player_info->source_id, player_info->format, buf);
68 printf("player %i rate    = %i\n",        player_info->source_id, player_info->rate);
69 printf("player %i left    = %i\n",        player_info->source_id, player_info->left_vol_scale );
70 printf("player %i right   = %i\n",        player_info->source_id, player_info->right_vol_scale );
71}
72void esd_print_sample_info( esd_sample_info_t *sample_info ) {
73}
74
75/* print all info to stdout */
76void esd_print_all_info( esd_info_t *all_info ) {
77 esd_player_info_t *player;
78 esd_sample_info_t *sample;
79
80
81 esd_print_server_info(all_info->server);
82
83 player = all_info->player_list;
84
85 while (player) {
86  esd_print_player_info(player);
87  player = player->next;
88 }
89
90 sample = all_info->sample_list;
91
92 while (sample) {
93  esd_print_sample_info(sample);
94  sample = sample->next;
95 }
96
97}
98
99/* retrieve server properties (sample rate, format, version number) */
100esd_server_info_t *esd_get_server_info( int esd ) {
101 esd_server_info_t * r;
102 struct roar_stream     s;
103 struct roar_connection con;
104 struct roar_message    m;
105
106 r = malloc(sizeof(esd_server_info_t));
107
108 if ( r == NULL )
109  return NULL;
110
111 r->version = 0; // seems to be static
112
113 con.fh    = esd;
114 m.cmd     = ROAR_CMD_SERVER_OINFO;
115 m.datalen = 0;
116
117 if ( roar_req(&con, &m, NULL) == -1 ) {
118  free(r);
119  return NULL;
120 }
121
122 if ( m.cmd != ROAR_CMD_OK ) {
123  free(r);
124  return NULL;
125 }
126
127 if ( roar_stream_m2s(&s, &m) == -1 ) {
128  free(r);
129  return NULL;
130 }
131
132 r->rate   = s.info.rate;
133 r->format = 0;
134
135 if ( s.info.channels  == 1 )
136  r->format |= ESD_MONO;
137 else
138  r->format |= ESD_STEREO;
139
140 if ( s.info.bits == 8 )
141  r->format |= ESD_BITS8;
142 else
143  r->format |= ESD_BITS16;
144
145 return r;
146}
147/* release all memory allocated for the server properties structure */
148void esd_free_server_info( esd_server_info_t *server_info ) {
149 if (server_info)
150  free(server_info);
151}
152
153/* retrieve all information from server */
154esd_info_t *esd_get_all_info( int esd ) {
155 esd_info_t * r;
156 int i;
157 int num;
158 int clients[ROAR_CLIENTS_MAX];
159 struct roar_client c;
160 struct roar_stream s;
161 struct roar_connection con[1];
162 esd_player_info_t * new_player, * cur = NULL; // = NULL to avoid gcc warning
163
164 con->fh = esd;
165
166 r = malloc(sizeof(esd_info_t));
167
168 if ( r == NULL )
169  return NULL;
170
171 r->server      = esd_get_server_info(esd);
172 r->player_list = NULL;
173 r->sample_list = NULL;
174
175 if ( (num = roar_list_clients(con, clients, ROAR_CLIENTS_MAX)) == -1 ) {
176  ROAR_ERR("esd_get_all_info(*): can not get client list");
177  num = 0;
178 }
179
180 for (i = 0; i < num; i++) {
181  if ( roar_get_client(con, &c, clients[i]) == -1 ) {
182   ROAR_ERR("esd_get_all_info(*): can not get client info");
183   continue;
184  }
185
186  if ( c.execed != -1 ) {
187   if ( roar_get_stream(con, &s, c.execed) == -1 ) {
188    ROAR_ERR("esd_get_all_info(*): can not get stream info");
189    continue;
190   }
191
192   if ( (new_player = malloc(sizeof(esd_player_info_t))) == NULL ) {
193    ROAR_ERR("esd_get_all_info(*): can not alloc memory for new player! BAD");
194    continue;
195   }
196
197   new_player->next = NULL;
198
199   new_player->source_id      = c.execed;
200   new_player->rate           = s.info.rate;
201
202   new_player->format         = ROAR_S2ESD(&s);
203//   sprintf(new_player->name, "roar stream %i", c.execed);
204   strncpy(new_player->name, c.name, ESD_NAME_MAX < ROAR_BUFFER_NAME ? ESD_NAME_MAX : ESD_NAME_MAX);
205
206   new_player->server         = r->server;
207   new_player->left_vol_scale = new_player->right_vol_scale = 256; // TODO: add data from the mixer
208
209   if ( r->player_list == NULL ) {
210     r->player_list = cur = new_player;
211   } else {
212     cur->next = new_player; // add to old player
213     cur       = new_player; // hop to next player
214   }
215
216  }
217 }
218
219 return r;
220}
221
222/* retrieve all information from server, and update until unsubsribed or closed */
223esd_info_t *esd_subscribe_all_info( int esd );
224
225/* call to update the info structure with new information, and call callbacks */
226esd_info_t *esd_update_info( int esd, esd_info_t *info,
227                             esd_update_info_callbacks_t *callbacks );
228esd_info_t *esd_unsubscribe_info( int esd );
229
230/* release all memory allocated for the esd info structure */
231void esd_free_all_info( esd_info_t *info ) {
232 esd_player_info_t *player, *oplayer;
233 esd_sample_info_t *sample, *osample;
234
235 if ( info != NULL ) {
236
237/*
238  if ( info->server )
239   free(info->server);
240*/
241  esd_free_server_info(info->server);
242
243
244/*
245  // TODO: do we need to free more?
246  if ( info->player_list )
247   free(info->player_list);
248
249  if ( info->sample_list )
250   free(info->sample_list);
251*/
252
253 player = info->player_list;
254
255 while (player) {
256  oplayer = player;
257  player  = player->next;
258
259  free(oplayer);
260 }
261
262 sample = info->sample_list;
263
264 while (sample) {
265  osample = sample;
266  sample  = sample->next;
267
268  free(osample);
269 }
270
271  free(info);
272 }
273}
274
275
276/* reset the volume panning for a stream */
277int esd_set_stream_pan( int esd, int stream_id,
278                        int left_scale, int right_scale ) {
279 struct roar_connection con;
280 struct roar_mixer_settings mixer;
281
282 con.fh = esd;
283
284 mixer.mixer[0] = left_scale;
285 mixer.mixer[1] = right_scale;
286
287 ROAR_DBG("esd_set_stream_pan(esd=%i, stream_id=%i, left_scale=%i, right_scale=%i) = ?",
288                esd, stream_id, left_scale, right_scale);
289
290 return roar_set_vol(&con, stream_id, &mixer, 2);
291}
292
293/* reset the default volume panning for a sample */
294int esd_set_default_sample_pan( int esd, int sample_id,
295                                int left_scale, int right_scale ) {
296 return -1;
297}
298
299/* see if the server is in stnaby, autostandby, etc */
300esd_standby_mode_t esd_get_standby_mode( int esd ) {
301 return roar_simple_get_standby(esd);
302}
303
304//ll
Note: See TracBrowser for help on using the repository browser.