[0] | 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 |
---|
| 9 | int esd_lock( int esd ) { |
---|
| 10 | return -1; |
---|
| 11 | } |
---|
| 12 | int esd_unlock( int esd ) { |
---|
| 13 | return -1; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | /* standby/resume will free/reclaim audio device so others may use it */ |
---|
| 17 | int 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 | |
---|
| 25 | int 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 */ |
---|
| 34 | void 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 | |
---|
[28] | 42 | if ( server_info->format & ESD_STEREO ) |
---|
[0] | 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 | |
---|
| 53 | void 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 | } |
---|
[26] | 72 | |
---|
[0] | 73 | void esd_print_sample_info( esd_sample_info_t *sample_info ) { |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /* print all info to stdout */ |
---|
| 77 | void esd_print_all_info( esd_info_t *all_info ) { |
---|
| 78 | esd_player_info_t *player; |
---|
| 79 | esd_sample_info_t *sample; |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | esd_print_server_info(all_info->server); |
---|
| 83 | |
---|
| 84 | player = all_info->player_list; |
---|
| 85 | |
---|
| 86 | while (player) { |
---|
| 87 | esd_print_player_info(player); |
---|
| 88 | player = player->next; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | sample = all_info->sample_list; |
---|
| 92 | |
---|
| 93 | while (sample) { |
---|
| 94 | esd_print_sample_info(sample); |
---|
| 95 | sample = sample->next; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /* retrieve server properties (sample rate, format, version number) */ |
---|
| 101 | esd_server_info_t *esd_get_server_info( int esd ) { |
---|
| 102 | esd_server_info_t * r; |
---|
| 103 | struct roar_stream s; |
---|
| 104 | struct roar_connection con; |
---|
| 105 | struct roar_message m; |
---|
| 106 | |
---|
| 107 | r = malloc(sizeof(esd_server_info_t)); |
---|
| 108 | |
---|
| 109 | if ( r == NULL ) |
---|
| 110 | return NULL; |
---|
| 111 | |
---|
| 112 | r->version = 0; // seems to be static |
---|
| 113 | |
---|
| 114 | con.fh = esd; |
---|
| 115 | m.cmd = ROAR_CMD_SERVER_OINFO; |
---|
| 116 | m.datalen = 0; |
---|
| 117 | |
---|
| 118 | if ( roar_req(&con, &m, NULL) == -1 ) { |
---|
| 119 | free(r); |
---|
| 120 | return NULL; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | if ( m.cmd != ROAR_CMD_OK ) { |
---|
| 124 | free(r); |
---|
| 125 | return NULL; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | if ( roar_stream_m2s(&s, &m) == -1 ) { |
---|
| 129 | free(r); |
---|
| 130 | return NULL; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | r->rate = s.info.rate; |
---|
| 134 | r->format = 0; |
---|
| 135 | |
---|
| 136 | if ( s.info.channels == 1 ) |
---|
| 137 | r->format |= ESD_MONO; |
---|
| 138 | else |
---|
| 139 | r->format |= ESD_STEREO; |
---|
| 140 | |
---|
| 141 | if ( s.info.bits == 8 ) |
---|
| 142 | r->format |= ESD_BITS8; |
---|
| 143 | else |
---|
| 144 | r->format |= ESD_BITS16; |
---|
| 145 | |
---|
| 146 | return r; |
---|
| 147 | } |
---|
| 148 | /* release all memory allocated for the server properties structure */ |
---|
| 149 | void esd_free_server_info( esd_server_info_t *server_info ) { |
---|
| 150 | if (server_info) |
---|
| 151 | free(server_info); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /* retrieve all information from server */ |
---|
| 155 | esd_info_t *esd_get_all_info( int esd ) { |
---|
| 156 | esd_info_t * r; |
---|
| 157 | int i; |
---|
| 158 | int num; |
---|
| 159 | int clients[ROAR_CLIENTS_MAX]; |
---|
| 160 | struct roar_client c; |
---|
| 161 | struct roar_stream s; |
---|
| 162 | struct roar_connection con[1]; |
---|
[26] | 163 | struct roar_mixer_settings mixer; |
---|
| 164 | int channels; |
---|
[0] | 165 | esd_player_info_t * new_player, * cur = NULL; // = NULL to avoid gcc warning |
---|
| 166 | |
---|
| 167 | con->fh = esd; |
---|
| 168 | |
---|
| 169 | r = malloc(sizeof(esd_info_t)); |
---|
| 170 | |
---|
| 171 | if ( r == NULL ) |
---|
| 172 | return NULL; |
---|
| 173 | |
---|
| 174 | r->server = esd_get_server_info(esd); |
---|
| 175 | r->player_list = NULL; |
---|
| 176 | r->sample_list = NULL; |
---|
| 177 | |
---|
| 178 | if ( (num = roar_list_clients(con, clients, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
| 179 | ROAR_ERR("esd_get_all_info(*): can not get client list"); |
---|
| 180 | num = 0; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | for (i = 0; i < num; i++) { |
---|
| 184 | if ( roar_get_client(con, &c, clients[i]) == -1 ) { |
---|
| 185 | ROAR_ERR("esd_get_all_info(*): can not get client info"); |
---|
| 186 | continue; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | if ( c.execed != -1 ) { |
---|
| 190 | if ( roar_get_stream(con, &s, c.execed) == -1 ) { |
---|
| 191 | ROAR_ERR("esd_get_all_info(*): can not get stream info"); |
---|
| 192 | continue; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | if ( (new_player = malloc(sizeof(esd_player_info_t))) == NULL ) { |
---|
| 196 | ROAR_ERR("esd_get_all_info(*): can not alloc memory for new player! BAD"); |
---|
| 197 | continue; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | new_player->next = NULL; |
---|
| 201 | |
---|
| 202 | new_player->source_id = c.execed; |
---|
| 203 | new_player->rate = s.info.rate; |
---|
| 204 | |
---|
| 205 | new_player->format = ROAR_S2ESD(&s); |
---|
| 206 | // sprintf(new_player->name, "roar stream %i", c.execed); |
---|
| 207 | strncpy(new_player->name, c.name, ESD_NAME_MAX < ROAR_BUFFER_NAME ? ESD_NAME_MAX : ESD_NAME_MAX); |
---|
| 208 | |
---|
| 209 | new_player->server = r->server; |
---|
[26] | 210 | |
---|
| 211 | if ( roar_get_vol(con, c.execed, &mixer, &channels) == -1 ) { |
---|
| 212 | ROAR_ERR("esd_get_all_info(*): can not get stream mixer info"); |
---|
| 213 | new_player->left_vol_scale = new_player->right_vol_scale = 256; |
---|
| 214 | } else { |
---|
| 215 | if ( channels == 1 ) { |
---|
| 216 | new_player->left_vol_scale = new_player->right_vol_scale = mixer.mixer[0] == 65536 ? 256 : mixer.mixer[0] / 256; |
---|
| 217 | } else { |
---|
| 218 | if ( channels != 2 ) { |
---|
| 219 | ROAR_ERR("esd_get_all_info(*): server seems to run in > 2 channel mode. ignoring any but the first two channels!"); |
---|
| 220 | } |
---|
| 221 | new_player->left_vol_scale = mixer.mixer[0] == 65536 ? 256 : mixer.mixer[0] / 256; |
---|
| 222 | new_player->right_vol_scale = mixer.mixer[1] == 65536 ? 256 : mixer.mixer[1] / 256; |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
[0] | 226 | |
---|
| 227 | if ( r->player_list == NULL ) { |
---|
| 228 | r->player_list = cur = new_player; |
---|
| 229 | } else { |
---|
| 230 | cur->next = new_player; // add to old player |
---|
| 231 | cur = new_player; // hop to next player |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | return r; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | /* retrieve all information from server, and update until unsubsribed or closed */ |
---|
| 241 | esd_info_t *esd_subscribe_all_info( int esd ); |
---|
| 242 | |
---|
| 243 | /* call to update the info structure with new information, and call callbacks */ |
---|
| 244 | esd_info_t *esd_update_info( int esd, esd_info_t *info, |
---|
| 245 | esd_update_info_callbacks_t *callbacks ); |
---|
| 246 | esd_info_t *esd_unsubscribe_info( int esd ); |
---|
| 247 | |
---|
| 248 | /* release all memory allocated for the esd info structure */ |
---|
| 249 | void esd_free_all_info( esd_info_t *info ) { |
---|
| 250 | esd_player_info_t *player, *oplayer; |
---|
| 251 | esd_sample_info_t *sample, *osample; |
---|
| 252 | |
---|
| 253 | if ( info != NULL ) { |
---|
| 254 | |
---|
| 255 | /* |
---|
| 256 | if ( info->server ) |
---|
| 257 | free(info->server); |
---|
| 258 | */ |
---|
| 259 | esd_free_server_info(info->server); |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | /* |
---|
| 263 | // TODO: do we need to free more? |
---|
| 264 | if ( info->player_list ) |
---|
| 265 | free(info->player_list); |
---|
| 266 | |
---|
| 267 | if ( info->sample_list ) |
---|
| 268 | free(info->sample_list); |
---|
| 269 | */ |
---|
| 270 | |
---|
| 271 | player = info->player_list; |
---|
| 272 | |
---|
| 273 | while (player) { |
---|
| 274 | oplayer = player; |
---|
| 275 | player = player->next; |
---|
| 276 | |
---|
| 277 | free(oplayer); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | sample = info->sample_list; |
---|
| 281 | |
---|
| 282 | while (sample) { |
---|
| 283 | osample = sample; |
---|
| 284 | sample = sample->next; |
---|
| 285 | |
---|
| 286 | free(osample); |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | free(info); |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | /* reset the volume panning for a stream */ |
---|
| 295 | int esd_set_stream_pan( int esd, int stream_id, |
---|
| 296 | int left_scale, int right_scale ) { |
---|
[17] | 297 | struct roar_connection con; |
---|
| 298 | struct roar_mixer_settings mixer; |
---|
| 299 | |
---|
| 300 | con.fh = esd; |
---|
| 301 | |
---|
[19] | 302 | mixer.mixer[0] = left_scale == 256 ? 65535 : left_scale * 256; |
---|
| 303 | mixer.mixer[1] = right_scale == 256 ? 65535 : right_scale * 256; |
---|
[17] | 304 | |
---|
| 305 | ROAR_DBG("esd_set_stream_pan(esd=%i, stream_id=%i, left_scale=%i, right_scale=%i) = ?", |
---|
| 306 | esd, stream_id, left_scale, right_scale); |
---|
| 307 | |
---|
| 308 | return roar_set_vol(&con, stream_id, &mixer, 2); |
---|
[0] | 309 | } |
---|
| 310 | |
---|
| 311 | /* reset the default volume panning for a sample */ |
---|
| 312 | int esd_set_default_sample_pan( int esd, int sample_id, |
---|
| 313 | int left_scale, int right_scale ) { |
---|
| 314 | return -1; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | /* see if the server is in stnaby, autostandby, etc */ |
---|
| 318 | esd_standby_mode_t esd_get_standby_mode( int esd ) { |
---|
| 319 | return roar_simple_get_standby(esd); |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | //ll |
---|