[668] | 1 | //req.c: |
---|
[486] | 2 | |
---|
[668] | 3 | /* |
---|
[3358] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[668] | 5 | * |
---|
| 6 | * This file is part of roard 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
[0] | 25 | |
---|
| 26 | #include "roard.h" |
---|
| 27 | |
---|
| 28 | int req_on_noop (int client, struct roar_message * mes, char * data) { |
---|
| 29 | mes->cmd = ROAR_CMD_OK; |
---|
| 30 | mes->datalen = 0; |
---|
| 31 | return 0; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | int req_on_identify (int client, struct roar_message * mes, char * data) { |
---|
| 35 | struct roar_client * c; |
---|
| 36 | int max_len; |
---|
| 37 | |
---|
| 38 | if ( mes->datalen < 1 ) |
---|
| 39 | return -1; |
---|
| 40 | |
---|
| 41 | clients_get(client, &c); |
---|
| 42 | |
---|
| 43 | if ( mes->data[0] == 1 ) { |
---|
[436] | 44 | if ( c->pid == -1 ) { |
---|
| 45 | c->pid = ROAR_NET2HOST32(*(uint32_t*)((mes->data)+1)); |
---|
[443] | 46 | ROAR_DBG("req_on_identify(): new PID: c->pid = %i", c->pid); |
---|
[436] | 47 | } |
---|
[0] | 48 | |
---|
[443] | 49 | ROAR_DBG("req_on_identify(): final PID: c->pid = %i", c->pid); |
---|
| 50 | |
---|
[0] | 51 | max_len = (mes->datalen - 5) < (ROAR_BUFFER_NAME-1) ? (mes->datalen - 5) : (ROAR_BUFFER_NAME-1); |
---|
| 52 | |
---|
| 53 | strncpy(c->name, mes->data + 5, max_len); |
---|
| 54 | c->name[max_len] = 0; |
---|
| 55 | |
---|
| 56 | mes->cmd = ROAR_CMD_OK; |
---|
| 57 | mes->datalen = 0; |
---|
| 58 | |
---|
| 59 | ROAR_DBG("req_on_identify(*): client=%i, pid=%i", client, c->pid); |
---|
| 60 | ROAR_DBG("req_on_identify(*) = 0"); |
---|
| 61 | return 0; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | return -1; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | int req_on_auth (int client, struct roar_message * mes, char * data) { |
---|
| 68 | // TODO: add code to support some auth. |
---|
| 69 | mes->cmd = ROAR_CMD_OK; |
---|
| 70 | mes->datalen = 0; |
---|
| 71 | return 0; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
[1162] | 75 | int req_on_whoami (int client, struct roar_message * mes, char * data) { |
---|
| 76 | mes->cmd = ROAR_CMD_OK; |
---|
| 77 | mes->datalen = 1; |
---|
| 78 | mes->data[0] = client; |
---|
| 79 | return 0; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
[0] | 83 | int req_on_new_stream (int client, struct roar_message * mes, char * data) { |
---|
| 84 | int stream; |
---|
| 85 | struct roar_stream * s; |
---|
[1812] | 86 | struct roar_stream * source_stream; |
---|
[1809] | 87 | struct roar_audio_info * info; |
---|
[1812] | 88 | struct roar_audio_info * source_info; |
---|
[0] | 89 | |
---|
[1904] | 90 | ROAR_DBG("req_on_new_stream(client=%i, ...): creating stream...", client); |
---|
[0] | 91 | if ((stream = streams_new()) == -1 ) |
---|
| 92 | return -1; |
---|
| 93 | |
---|
[1904] | 94 | ROAR_DBG("req_on_new_stream(client=%i, ...): getting stream...", client); |
---|
[0] | 95 | if ( streams_get(stream, (struct roar_stream_server **)&s) == -1 ) { |
---|
| 96 | streams_delete(stream); |
---|
| 97 | return -1; |
---|
| 98 | } |
---|
| 99 | |
---|
[1904] | 100 | ROAR_DBG("req_on_new_stream(client=%i, ...): set client of stream...", client); |
---|
[0] | 101 | if ( client_stream_add(client, stream) == -1 ) { |
---|
| 102 | streams_delete(stream); |
---|
| 103 | return -1; |
---|
| 104 | } |
---|
| 105 | |
---|
[1904] | 106 | ROAR_DBG("req_on_new_stream(client=%i, ...): loading stream from message...", client); |
---|
[0] | 107 | if ( roar_stream_m2s(s, mes) == -1 ) { |
---|
| 108 | streams_delete(stream); |
---|
| 109 | return -1; |
---|
| 110 | } |
---|
| 111 | |
---|
[1904] | 112 | ROAR_DBG("req_on_new_stream(client=%i, ...): setting id and codec of stream...", client); |
---|
[486] | 113 | ROAR_STREAM(s)->id = stream; // roar_stream_m2s() resets this |
---|
[539] | 114 | ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM(s)->info.codec; |
---|
[486] | 115 | |
---|
[1904] | 116 | ROAR_DBG("req_on_new_stream(client=%i, ...): setting direction stream...", client); |
---|
[1900] | 117 | // int streams_set_dir (int id, int dir, int defaults) |
---|
| 118 | if ( streams_set_dir(stream, ROAR_STREAM(s)->dir, 1) == -1 ) { |
---|
| 119 | streams_delete(stream); |
---|
| 120 | return -1; |
---|
| 121 | } |
---|
| 122 | |
---|
[1904] | 123 | ROAR_DBG("req_on_new_stream(client=%i, ...): setting up direction specific stream settings...", client); |
---|
[1809] | 124 | switch (ROAR_STREAM(s)->dir) { |
---|
| 125 | case ROAR_DIR_LIGHT_IN: |
---|
| 126 | case ROAR_DIR_LIGHT_OUT: |
---|
[2497] | 127 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1809] | 128 | info = &(ROAR_STREAM(s)->info); |
---|
| 129 | |
---|
| 130 | info->channels = 0; |
---|
| 131 | info->bits = 0; |
---|
| 132 | info->rate = 0; |
---|
[2497] | 133 | #else |
---|
| 134 | streams_delete(stream); |
---|
| 135 | return -1; |
---|
| 136 | #endif |
---|
[1809] | 137 | |
---|
| 138 | break; |
---|
[1848] | 139 | case ROAR_DIR_MIDI_IN: |
---|
| 140 | case ROAR_DIR_MIDI_OUT: |
---|
[2497] | 141 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1848] | 142 | info = &(ROAR_STREAM(s)->info); |
---|
| 143 | |
---|
[2402] | 144 | info->channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 145 | info->bits = ROAR_MIDI_BITS; |
---|
| 146 | info->rate = 0; |
---|
[2497] | 147 | #else |
---|
| 148 | streams_delete(stream); |
---|
| 149 | return -1; |
---|
| 150 | #endif |
---|
[1848] | 151 | |
---|
| 152 | break; |
---|
| 153 | |
---|
[2250] | 154 | case ROAR_DIR_RAW_IN: |
---|
[2497] | 155 | #ifndef ROAR_WITHOUT_DCOMP_RAW |
---|
[2250] | 156 | if ( ROAR_STREAM(s)->pos_rel_id == -1 || |
---|
| 157 | ROAR_STREAM(s)->pos_rel_id == stream || |
---|
| 158 | streams_get_dir(ROAR_STREAM(s)->pos_rel_id) != ROAR_DIR_RAW_OUT |
---|
| 159 | ) { |
---|
| 160 | ROAR_STREAM(s)->pos_rel_id = -1; // force this here as it will try to delete itself while deleting |
---|
| 161 | // in case rel_id == stream |
---|
| 162 | streams_delete(stream); |
---|
| 163 | return -1; |
---|
| 164 | } |
---|
[2497] | 165 | #else |
---|
| 166 | case ROAR_DIR_RAW_OUT: |
---|
| 167 | streams_delete(stream); |
---|
| 168 | return -1; |
---|
| 169 | #endif |
---|
[2250] | 170 | |
---|
| 171 | break; |
---|
[1812] | 172 | case ROAR_DIR_THRU: |
---|
[1815] | 173 | |
---|
| 174 | if ( ROAR_STREAM(s)->pos_rel_id == -1 || ROAR_STREAM(s)->pos_rel_id == stream ) { |
---|
[1861] | 175 | ROAR_STREAM(s)->pos_rel_id = -1; // force this here as it will try to delete itself while deleting |
---|
| 176 | // in case rel_id == stream |
---|
[1815] | 177 | streams_delete(stream); |
---|
| 178 | return -1; |
---|
| 179 | } |
---|
| 180 | |
---|
[1812] | 181 | if ( streams_get(ROAR_STREAM(s)->pos_rel_id, (struct roar_stream_server **)&source_stream) == -1 ) { |
---|
| 182 | streams_delete(stream); |
---|
| 183 | return -1; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | info = &(ROAR_STREAM(s)->info); |
---|
| 187 | source_info = &(ROAR_STREAM(source_stream)->info); |
---|
| 188 | |
---|
| 189 | info->channels = source_info->channels; |
---|
| 190 | info->bits = source_info->bits; |
---|
| 191 | info->rate = source_info->rate; |
---|
| 192 | info->codec = source_info->codec; |
---|
[1840] | 193 | ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM_SERVER(source_stream)->codec_orgi; |
---|
[1812] | 194 | |
---|
| 195 | break; |
---|
[3672] | 196 | case ROAR_DIR_FILTER: |
---|
| 197 | info = &(ROAR_STREAM(s)->info); |
---|
| 198 | |
---|
| 199 | if ( ROAR_STREAM(s)->pos_rel_id == -1 ) { |
---|
| 200 | source_info = g_sa; |
---|
| 201 | } else { |
---|
| 202 | if ( streams_get(ROAR_STREAM(s)->pos_rel_id, (struct roar_stream_server **)&source_stream) == -1 ) { |
---|
| 203 | streams_delete(stream); |
---|
| 204 | return -1; |
---|
| 205 | } |
---|
| 206 | source_info = &(ROAR_STREAM(source_stream)->info); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | if ( info->channels != source_info->channels || info->bits != source_info->bits || |
---|
| 210 | info->codec != source_info->codec || info->rate != source_info->rate ) { |
---|
| 211 | // the stream parameters don't match the one of the stream being filtered. |
---|
| 212 | // -> delete and reject the stream. |
---|
| 213 | streams_delete(stream); |
---|
| 214 | return -1; |
---|
| 215 | } |
---|
| 216 | break; |
---|
[1809] | 217 | } |
---|
| 218 | |
---|
[1904] | 219 | ROAR_DBG("req_on_new_stream(client=%i, ...): returning (OK)...", client); |
---|
| 220 | |
---|
[0] | 221 | mes->cmd = ROAR_CMD_OK; |
---|
| 222 | mes->stream = stream; |
---|
| 223 | mes->datalen = 0; |
---|
| 224 | |
---|
| 225 | return 0; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | int req_on_exec_stream (int client, struct roar_message * mes, char * data) { |
---|
| 229 | int r; |
---|
| 230 | |
---|
[1904] | 231 | ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): execing stream", client, mes->stream); |
---|
| 232 | |
---|
[0] | 233 | if ( (r = client_stream_exec(client, mes->stream)) == -1 ) |
---|
| 234 | return -1; |
---|
| 235 | |
---|
[1904] | 236 | ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): returning (OK)...", client, mes->stream); |
---|
[0] | 237 | mes->cmd = ROAR_CMD_OK; |
---|
| 238 | mes->datalen = 0; |
---|
| 239 | |
---|
| 240 | return 0; |
---|
| 241 | } |
---|
| 242 | |
---|
[77] | 243 | int req_on_con_stream (int client, struct roar_message * mes, char * data) { |
---|
| 244 | char host[80] = {0}; |
---|
| 245 | int port = 0; |
---|
| 246 | int type; |
---|
| 247 | int fh; |
---|
| 248 | int len; |
---|
| 249 | |
---|
| 250 | if ( mes->datalen < 4 ) |
---|
| 251 | return -1; |
---|
| 252 | |
---|
| 253 | if ( *(mes->data) != 0 ) |
---|
| 254 | return -1; |
---|
| 255 | |
---|
[80] | 256 | if ( mes->datalen > 80 ) // we do not support long messages here |
---|
| 257 | return -1; |
---|
| 258 | |
---|
[77] | 259 | type = (unsigned)mes->data[1]; |
---|
[79] | 260 | port = ROAR_NET2HOST16(((uint16_t*)mes->data)[1]); |
---|
[77] | 261 | |
---|
[80] | 262 | len = mes->datalen - 4; |
---|
[77] | 263 | |
---|
[84] | 264 | strncpy(host, &(mes->data[4]), len); |
---|
[77] | 265 | host[len] = 0; |
---|
| 266 | |
---|
| 267 | if ( type > ROAR_SOCKET_TYPE_MAX ) |
---|
| 268 | return -1; |
---|
| 269 | |
---|
| 270 | if ( type == ROAR_SOCKET_TYPE_FILE ) // disabled because of security resons |
---|
| 271 | return -1; |
---|
| 272 | |
---|
| 273 | if ( type == ROAR_SOCKET_TYPE_FORK ) // why should we connect to ourself? |
---|
| 274 | return -1; |
---|
| 275 | |
---|
[525] | 276 | ROAR_DBG("req_on_con_stream(*): CONNECT(type=%i, host='%s', port=%i)", type, host, port); |
---|
| 277 | |
---|
[77] | 278 | if ( (fh = roar_socket_open(ROAR_SOCKET_MODE_CONNECT, type, host, port)) == -1 ) |
---|
| 279 | return -1; |
---|
| 280 | |
---|
[78] | 281 | if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) { |
---|
| 282 | close(fh); |
---|
| 283 | return 1; |
---|
| 284 | } |
---|
| 285 | |
---|
[757] | 286 | mes->datalen = 0; |
---|
| 287 | mes->cmd = ROAR_CMD_OK; |
---|
| 288 | |
---|
[78] | 289 | return 0; |
---|
[757] | 290 | } |
---|
| 291 | |
---|
| 292 | int req_on_passfh (int client, struct roar_message * mes, char * data) { |
---|
[3714] | 293 | int sock = clients_get_fh(client); |
---|
[3720] | 294 | int16_t * d = (int16_t*)mes->data; |
---|
[757] | 295 | int fh; |
---|
[3714] | 296 | int i; |
---|
[757] | 297 | |
---|
| 298 | if ( (fh = roar_socket_recv_fh(sock, NULL, NULL)) == -1 ) |
---|
| 299 | return -1; |
---|
| 300 | |
---|
[3720] | 301 | if ( (int16_t)mes->stream != -1 ) { // stream pass: |
---|
[3714] | 302 | if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) { |
---|
| 303 | close(fh); |
---|
| 304 | return 1; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | mes->datalen = 0; |
---|
| 308 | mes->cmd = ROAR_CMD_OK; |
---|
| 309 | |
---|
| 310 | return 0; |
---|
[757] | 311 | } |
---|
| 312 | |
---|
[3714] | 313 | // non-stream pass: |
---|
| 314 | |
---|
| 315 | /* |
---|
| 316 | 0: Version, 16 |
---|
| 317 | 1: Flags, 16 |
---|
| 318 | 2: Protocol, 16 |
---|
| 319 | 3: Byteorder 16 |
---|
| 320 | Options... |
---|
| 321 | */ |
---|
| 322 | |
---|
| 323 | if ( mes->datalen < 4*2 ) |
---|
| 324 | return -1; |
---|
| 325 | |
---|
| 326 | for (i = 0; i < 4; i++) { |
---|
| 327 | d[i] = ROAR_NET2HOST16(d[i]); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | if ( d[0] != 0 ) // version |
---|
| 331 | return -1; |
---|
| 332 | |
---|
| 333 | if ( d[1] != 0 ) // flags |
---|
| 334 | return -1; |
---|
| 335 | |
---|
| 336 | if ( d[2] != ROAR_PROTO_ROARAUDIO ) // protocol |
---|
| 337 | return -1; |
---|
| 338 | |
---|
| 339 | if ( d[3] != ROAR_BYTEORDER_NETWORK ) // byte order |
---|
| 340 | return -1; |
---|
| 341 | |
---|
| 342 | if ( (client = clients_new()) == -1 ) |
---|
| 343 | return -1; |
---|
| 344 | |
---|
| 345 | if ( clients_set_fh(client, fh) == -1 ) { |
---|
| 346 | clients_delete(client); |
---|
| 347 | return -1; |
---|
| 348 | } |
---|
[78] | 349 | |
---|
| 350 | mes->datalen = 0; |
---|
| 351 | mes->cmd = ROAR_CMD_OK; |
---|
[757] | 352 | |
---|
[3720] | 353 | return 0; |
---|
[77] | 354 | } |
---|
| 355 | |
---|
[1493] | 356 | #ifdef ROAR_SUPPORT_META |
---|
[0] | 357 | int req_on_set_meta (int client, struct roar_message * mes, char * data) { |
---|
[92] | 358 | int type; |
---|
| 359 | int mode; |
---|
| 360 | int namelen, vallen; |
---|
[99] | 361 | char val[255+1]; |
---|
[92] | 362 | char name[ROAR_META_MAX_NAMELEN+1]; |
---|
| 363 | |
---|
| 364 | if ( mes->datalen < 3 ) |
---|
| 365 | return -1; |
---|
| 366 | |
---|
| 367 | if ( mes->data[0] != 0 ) // version |
---|
| 368 | return -1; |
---|
| 369 | |
---|
| 370 | mode = (unsigned) mes->data[1]; |
---|
| 371 | type = (unsigned) mes->data[2]; |
---|
| 372 | |
---|
[99] | 373 | ROAR_DBG("req_on_set_meta(*): mode=%i, type=%i", mode, type); |
---|
| 374 | |
---|
[92] | 375 | if ( mode == ROAR_META_MODE_CLEAR ) { |
---|
| 376 | stream_meta_clear(mes->stream); |
---|
| 377 | mes->datalen = 0; |
---|
| 378 | mes->cmd = ROAR_CMD_OK; |
---|
| 379 | return 0; |
---|
| 380 | } else if ( mode == ROAR_META_MODE_DELETE ) { // unsuppoerted at the moment |
---|
[1038] | 381 | return -1; |
---|
| 382 | } else if ( mode == ROAR_META_MODE_FINALIZE ) { |
---|
| 383 | stream_meta_finalize(mes->stream); |
---|
| 384 | mes->datalen = 0; |
---|
| 385 | mes->cmd = ROAR_CMD_OK; |
---|
| 386 | return 0; |
---|
[92] | 387 | } else if ( mode == ROAR_META_MODE_SET || mode == ROAR_META_MODE_ADD ) { |
---|
| 388 | if ( mes->datalen < 5 ) |
---|
| 389 | return -1; |
---|
| 390 | |
---|
| 391 | namelen = (unsigned) mes->data[3]; |
---|
| 392 | vallen = (unsigned) mes->data[4]; |
---|
| 393 | |
---|
[99] | 394 | ROAR_DBG("req_on_set_meta(*): namelen=%i, vallen=%i", namelen, vallen); |
---|
| 395 | |
---|
[92] | 396 | if ( mes->datalen < (5 + namelen + vallen) ) |
---|
| 397 | return -1; |
---|
| 398 | |
---|
| 399 | if ( namelen > ROAR_META_MAX_NAMELEN ) |
---|
| 400 | return -1; |
---|
| 401 | |
---|
| 402 | strncpy(name, &(mes->data[5]), namelen); |
---|
| 403 | name[namelen] = 0; |
---|
| 404 | |
---|
[99] | 405 | if ( vallen > 255 ) |
---|
[92] | 406 | return -1; |
---|
| 407 | |
---|
| 408 | strncpy(val, &(mes->data[5+namelen]), vallen); |
---|
| 409 | val[vallen] = 0; |
---|
| 410 | |
---|
| 411 | if ( mode == ROAR_META_MODE_SET ) { |
---|
| 412 | if ( stream_meta_set(mes->stream, type, name, val) == -1 ) |
---|
| 413 | return -1; |
---|
| 414 | } else { |
---|
| 415 | if ( stream_meta_add(mes->stream, type, name, val) == -1 ) |
---|
| 416 | return -1; |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | mes->datalen = 0; |
---|
| 420 | mes->cmd = ROAR_CMD_OK; |
---|
| 421 | return 0; |
---|
| 422 | } else { // unknown mode! |
---|
| 423 | return -1; |
---|
| 424 | } |
---|
| 425 | |
---|
[0] | 426 | return -1; |
---|
| 427 | } |
---|
| 428 | |
---|
[100] | 429 | int req_on_get_meta (int client, struct roar_message * mes, char * data) { |
---|
[101] | 430 | int vallen; |
---|
| 431 | int type; |
---|
[107] | 432 | char val[LIBROAR_BUFFER_MSGDATA-1]; |
---|
[101] | 433 | |
---|
| 434 | if ( mes->datalen != 2 ) |
---|
| 435 | return -1; |
---|
| 436 | |
---|
| 437 | if ( mes->data[0] != 0 ) // version |
---|
| 438 | return -1; |
---|
| 439 | |
---|
| 440 | type = (unsigned) mes->data[1]; |
---|
| 441 | |
---|
| 442 | if ( stream_meta_get(mes->stream, type, NULL, val, LIBROAR_BUFFER_MSGDATA-2) == -1 ) |
---|
| 443 | return -1; |
---|
| 444 | |
---|
| 445 | vallen = strlen(val); |
---|
| 446 | |
---|
| 447 | mes->cmd = ROAR_CMD_OK; |
---|
| 448 | mes->datalen = 2 + vallen; |
---|
| 449 | |
---|
| 450 | mes->data[0] = 0; |
---|
| 451 | mes->data[1] = (unsigned char) vallen; |
---|
| 452 | |
---|
[107] | 453 | val[vallen] = 0; |
---|
| 454 | |
---|
| 455 | strncpy(&(mes->data[2]), val, vallen+1); |
---|
[101] | 456 | |
---|
| 457 | return 0; |
---|
[100] | 458 | } |
---|
[0] | 459 | |
---|
[113] | 460 | int req_on_list_meta (int client, struct roar_message * mes, char * data) { |
---|
| 461 | int i; |
---|
| 462 | int len = 0; |
---|
| 463 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 464 | |
---|
| 465 | if ( mes->datalen != 1 ) |
---|
| 466 | return -1; |
---|
| 467 | |
---|
| 468 | if ( mes->data[0] != 0 ) // version |
---|
| 469 | return -1; |
---|
| 470 | |
---|
| 471 | if ( (len = stream_meta_list(mes->stream, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 472 | return -1; |
---|
| 473 | |
---|
| 474 | mes->cmd = ROAR_CMD_OK; |
---|
| 475 | mes->datalen = 1 + len; |
---|
| 476 | mes->data[0] = 0; |
---|
| 477 | |
---|
| 478 | for (i = 0; i < len; i++) |
---|
| 479 | mes->data[i+1] = types[i]; |
---|
| 480 | |
---|
| 481 | return 0; |
---|
| 482 | } |
---|
[1493] | 483 | #endif |
---|
[113] | 484 | |
---|
[0] | 485 | int req_on_server_oinfo (int client, struct roar_message * mes, char * data) { |
---|
| 486 | struct roar_stream s; |
---|
| 487 | //ROAR_DIR_OUTPUT |
---|
| 488 | |
---|
[966] | 489 | memset(&s, 0, sizeof(struct roar_stream)); |
---|
[964] | 490 | |
---|
[977] | 491 | s.dir = ROAR_DIR_MIXING; |
---|
[0] | 492 | s.pos_rel_id = -1; |
---|
| 493 | s.info.rate = g_sa->rate; |
---|
| 494 | s.info.bits = g_sa->bits; |
---|
| 495 | s.info.channels = g_sa->channels; |
---|
| 496 | s.info.codec = g_sa->codec; |
---|
[977] | 497 | s.pos = g_pos; |
---|
[0] | 498 | |
---|
| 499 | if ( roar_stream_s2m(&s, mes) == -1 ) |
---|
| 500 | return -1; |
---|
| 501 | |
---|
| 502 | mes->cmd = ROAR_CMD_OK; |
---|
| 503 | |
---|
| 504 | return 0; |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | |
---|
| 508 | int req_on_get_standby (int client, struct roar_message * mes, char * data) { |
---|
| 509 | mes->cmd = ROAR_CMD_OK; |
---|
| 510 | mes->datalen = 2; |
---|
| 511 | |
---|
| 512 | *((uint16_t*)mes->data) = ROAR_HOST2NET16((unsigned) g_standby); |
---|
| 513 | |
---|
| 514 | return 0; |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | int req_on_set_standby (int client, struct roar_message * mes, char * data) { |
---|
| 518 | if ( mes->datalen != 2 ) |
---|
| 519 | return -1; |
---|
| 520 | |
---|
| 521 | g_standby = ROAR_NET2HOST16(*((uint16_t*)mes->data)); |
---|
| 522 | |
---|
| 523 | mes->cmd = ROAR_CMD_OK; |
---|
| 524 | mes->datalen = 0; |
---|
| 525 | |
---|
| 526 | return 0; |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | int req_on_exit (int client, struct roar_message * mes, char * data) { |
---|
[575] | 530 | int term = 0; |
---|
| 531 | |
---|
| 532 | if ( mes->datalen == 1 ) |
---|
| 533 | term = mes->data[0]; |
---|
| 534 | |
---|
[0] | 535 | mes->cmd = ROAR_CMD_OK; |
---|
| 536 | mes->datalen = 0; |
---|
| 537 | |
---|
[576] | 538 | ROAR_DBG("req_on_exit(*): term=%i", term); |
---|
| 539 | |
---|
[575] | 540 | if ( term ) { |
---|
| 541 | cleanup_listen_socket(1); |
---|
| 542 | } else { |
---|
| 543 | alive = 0; |
---|
| 544 | } |
---|
[0] | 545 | |
---|
| 546 | return 0; |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | int req_on_list_clients(int client, struct roar_message * mes, char * data) { |
---|
| 550 | unsigned char filter, cmp; |
---|
| 551 | uint32_t id; |
---|
| 552 | int clients[ROAR_CLIENTS_MAX]; |
---|
| 553 | int i, c = 0; |
---|
| 554 | |
---|
| 555 | if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 ) |
---|
| 556 | return -1; |
---|
| 557 | |
---|
| 558 | // TODO: add code to support filter |
---|
| 559 | if ( filter != ROAR_CTL_FILTER_ANY ) |
---|
| 560 | return -1; |
---|
| 561 | |
---|
| 562 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 563 | if ( g_clients[i] != NULL ) { |
---|
| 564 | clients[c++] = i; |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | roar_ctl_ia2m(mes, clients, c); |
---|
| 569 | |
---|
| 570 | mes->cmd = ROAR_CMD_OK; |
---|
| 571 | |
---|
| 572 | return 0; |
---|
| 573 | } |
---|
| 574 | int req_on_list_streams(int client, struct roar_message * mes, char * data) { |
---|
| 575 | unsigned char filter, cmp; |
---|
| 576 | uint32_t id; |
---|
| 577 | int streams[ROAR_STREAMS_MAX]; |
---|
| 578 | int i, c = 0; |
---|
| 579 | |
---|
| 580 | if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 ) |
---|
| 581 | return -1; |
---|
| 582 | |
---|
| 583 | // TODO: add code to support filter |
---|
| 584 | if ( filter != ROAR_CTL_FILTER_ANY ) |
---|
| 585 | return -1; |
---|
| 586 | |
---|
| 587 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 588 | if ( g_streams[i] != NULL ) { |
---|
| 589 | streams[c++] = i; |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | roar_ctl_ia2m(mes, streams, c); |
---|
| 594 | |
---|
| 595 | mes->cmd = ROAR_CMD_OK; |
---|
| 596 | |
---|
| 597 | return 0; |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | int req_on_get_client (int client, struct roar_message * mes, char * data) { |
---|
| 601 | struct roar_client * c; |
---|
| 602 | |
---|
| 603 | if ( mes->datalen != 1 ) |
---|
| 604 | return -1; |
---|
| 605 | |
---|
| 606 | if ( clients_get(mes->data[0], &c) == -1 ) |
---|
| 607 | return -1; |
---|
| 608 | |
---|
| 609 | mes->cmd = ROAR_CMD_OK; |
---|
| 610 | |
---|
| 611 | return roar_ctl_c2m(mes, c); |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | int req_on_get_stream (int client, struct roar_message * mes, char * data) { |
---|
| 615 | struct roar_stream_server * s; |
---|
| 616 | |
---|
| 617 | if ( mes->datalen != 1 ) |
---|
| 618 | return -1; |
---|
| 619 | |
---|
| 620 | if ( streams_get(mes->data[0], &s) == -1 ) |
---|
| 621 | return -1; |
---|
| 622 | |
---|
| 623 | mes->cmd = ROAR_CMD_OK; |
---|
[465] | 624 | mes->stream = mes->data[0]; |
---|
[0] | 625 | |
---|
| 626 | return roar_stream_s2m(ROAR_STREAM(s), mes); |
---|
| 627 | } |
---|
| 628 | |
---|
[465] | 629 | int req_on_get_stream_para (int client, struct roar_message * mes, char * data) { |
---|
| 630 | struct roar_stream * s; |
---|
[963] | 631 | struct roar_stream_server * ss; |
---|
[465] | 632 | struct roar_audio_info * audio_info; |
---|
| 633 | uint16_t * d = (uint16_t *) mes->data; |
---|
| 634 | int i; |
---|
[1842] | 635 | char * str; |
---|
[465] | 636 | |
---|
| 637 | if ( mes->datalen != 4 ) |
---|
| 638 | return -1; |
---|
| 639 | |
---|
| 640 | for (i = 0; i < mes->datalen/2; i++) { |
---|
| 641 | d[i] = ROAR_NET2HOST16(d[i]); |
---|
| 642 | } |
---|
| 643 | |
---|
[1842] | 644 | if ( d[0] != 0 ) { |
---|
[465] | 645 | ROAR_WARN("req_on_get_stream_para(*): unsupported command version: %i, %i", d[0], d[1]); |
---|
| 646 | return -1; |
---|
| 647 | } |
---|
| 648 | |
---|
[1842] | 649 | switch (d[1]) { |
---|
| 650 | case ROAR_STREAM_PARA_INFO: |
---|
| 651 | if ( streams_get(mes->stream, &ss) == -1 ) { |
---|
| 652 | ROAR_WARN("req_on_get_stream_para(*): request on non existing (or other error?) stream %i", mes->stream); |
---|
| 653 | return -1; |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | if ( streams_calc_delay(mes->stream) == -1 ) { |
---|
| 657 | ROAR_WARN("req_on_get_stream_para(*): can not calc delay for stream %i", mes->stream); |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | s = ROAR_STREAM(ss); |
---|
[465] | 661 | |
---|
[1842] | 662 | audio_info = &(s->info); |
---|
| 663 | |
---|
[3630] | 664 | mes->datalen = 2*12; |
---|
[1842] | 665 | |
---|
[3213] | 666 | d[ 2] = ROAR_OUTPUT_CALC_OUTBUFSIZE(audio_info); |
---|
| 667 | d[ 3] = ss->pre_underruns; |
---|
| 668 | d[ 4] = ss->post_underruns; |
---|
| 669 | d[ 5] = ss->codec_orgi; |
---|
| 670 | d[ 6] = (ss->flags & 0xFFFF) | (ss->primary ? ROAR_FLAG_PRIMARY : 0) | (ss->driver_id != -1 ? ROAR_FLAG_OUTPUT : 0); |
---|
| 671 | d[ 7] = ss->delay/1000; |
---|
| 672 | d[ 8] = ss->state; |
---|
| 673 | d[ 9] = (ss->flags & 0xFFFF0000) >> 16; |
---|
| 674 | d[10] = ss->mixer_stream; |
---|
[3630] | 675 | d[11] = ss->role; |
---|
[1842] | 676 | |
---|
| 677 | ROAR_DBG("req_on_get_stream_para(*): ss->driver_id=%i", ss->driver_id); |
---|
| 678 | |
---|
| 679 | ROAR_DBG("req_on_get_stream_para(*): delay=%i, send delay=%i", ss->delay, d[7]); |
---|
[465] | 680 | |
---|
[1842] | 681 | for (i = 0; i < mes->datalen/2; i++) { |
---|
| 682 | d[i] = ROAR_HOST2NET16(d[i]); |
---|
| 683 | } |
---|
[1156] | 684 | |
---|
[1842] | 685 | mes->pos = s->pos; |
---|
| 686 | break; |
---|
| 687 | |
---|
| 688 | case ROAR_STREAM_PARA_NAME: |
---|
| 689 | str = streams_get_name(mes->stream); |
---|
| 690 | |
---|
| 691 | if ( str == NULL ) |
---|
| 692 | return -1; |
---|
[1151] | 693 | |
---|
[1842] | 694 | mes->datalen = 4 + strlen(str); |
---|
| 695 | |
---|
| 696 | if ( mes->datalen > LIBROAR_BUFFER_MSGDATA ) |
---|
| 697 | return -1; |
---|
| 698 | |
---|
| 699 | strncpy(((char*)&(mes->data))+4, str, mes->datalen); |
---|
| 700 | |
---|
| 701 | d[0] = ROAR_HOST2NET16(d[0]); |
---|
| 702 | d[1] = ROAR_HOST2NET16(d[1]); |
---|
| 703 | break; |
---|
| 704 | |
---|
[3539] | 705 | case ROAR_STREAM_PARA_CHANMAP: |
---|
| 706 | if ( streams_get(mes->stream, &ss) == -1 ) { |
---|
| 707 | ROAR_WARN("req_on_get_stream_para(*): request on non existing (or other error?) stream %i", mes->stream); |
---|
| 708 | return -1; |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | s = ROAR_STREAM(ss); |
---|
| 712 | |
---|
| 713 | memcpy(&(mes->data[4]), ss->chanmap.in, s->info.channels); |
---|
| 714 | mes->datalen = 2*2 + s->info.channels; |
---|
| 715 | |
---|
| 716 | d[0] = ROAR_HOST2NET16(d[0]); |
---|
| 717 | d[1] = ROAR_HOST2NET16(d[1]); |
---|
| 718 | break; |
---|
| 719 | |
---|
[1842] | 720 | default: |
---|
| 721 | ROAR_WARN("req_on_get_stream_para(*): unsupported command: %i", d[1]); |
---|
| 722 | return -1; |
---|
[465] | 723 | } |
---|
| 724 | |
---|
| 725 | mes->cmd = ROAR_CMD_OK; |
---|
| 726 | return 0; |
---|
| 727 | } |
---|
| 728 | |
---|
[1043] | 729 | int req_on_set_stream_para (int client, struct roar_message * mes, char * data) { |
---|
| 730 | uint16_t * d = (uint16_t *) mes->data; |
---|
| 731 | int i; |
---|
| 732 | |
---|
[3542] | 733 | if ( mes->datalen < 2*2 ) |
---|
[1043] | 734 | return -1; |
---|
| 735 | |
---|
[3542] | 736 | for (i = 0; i < 2; i++) { |
---|
[1043] | 737 | d[i] = ROAR_NET2HOST16(d[i]); |
---|
| 738 | } |
---|
| 739 | |
---|
[3542] | 740 | if ( d[0] != 0 ) |
---|
[1043] | 741 | return -1; |
---|
[3542] | 742 | |
---|
| 743 | switch (d[1]) { |
---|
| 744 | case ROAR_STREAM_PARA_FLAGS: |
---|
| 745 | if ( mes->datalen != 2*4 ) |
---|
| 746 | return -1; |
---|
| 747 | |
---|
| 748 | d[2] = ROAR_NET2HOST16(d[2]); |
---|
| 749 | d[3] = ROAR_NET2HOST16(d[3]); |
---|
| 750 | |
---|
| 751 | ROAR_DBG("req_on_set_stream_para(*): request seems to be valid"); |
---|
| 752 | |
---|
| 753 | if ( d[2] == ROAR_RESET_FLAG ) { |
---|
| 754 | if ( streams_reset_flag(mes->stream, d[3]) == -1 ) |
---|
| 755 | return -1; |
---|
| 756 | } else { |
---|
| 757 | if ( streams_set_flag(mes->stream, d[3]) == -1 ) |
---|
| 758 | return -1; |
---|
| 759 | } |
---|
| 760 | break; |
---|
| 761 | case ROAR_STREAM_PARA_CHANMAP: |
---|
| 762 | if ( streams_set_map(mes->stream, &(mes->data[4]), mes->datalen - 4) == -1 ) |
---|
| 763 | return -1; |
---|
| 764 | break; |
---|
[3696] | 765 | case ROAR_STREAM_PARA_ROLE: |
---|
| 766 | if ( mes->datalen != 2*3 ) |
---|
| 767 | return -1; |
---|
| 768 | |
---|
| 769 | d[2] = ROAR_NET2HOST16(d[2]); |
---|
| 770 | |
---|
| 771 | if ( streams_set_role(mes->stream, d[2]) == -1 ) |
---|
| 772 | return -1; |
---|
| 773 | break; |
---|
[3542] | 774 | default: |
---|
| 775 | ROAR_WARN("req_on_set_stream_para(*): unsupported command version: %i, %i", d[0], d[1]); |
---|
| 776 | return -1; |
---|
| 777 | break; |
---|
[1043] | 778 | } |
---|
| 779 | |
---|
| 780 | mes->cmd = ROAR_CMD_OK; |
---|
| 781 | mes->datalen = 0; |
---|
| 782 | |
---|
[3542] | 783 | return 0; |
---|
[1043] | 784 | } |
---|
| 785 | |
---|
[0] | 786 | int req_on_kick (int client, struct roar_message * mes, char * data) { |
---|
[17] | 787 | uint16_t * info = (uint16_t *) mes->data; |
---|
[0] | 788 | |
---|
| 789 | if ( mes->datalen != 4 ) |
---|
| 790 | return -1; |
---|
| 791 | |
---|
[251] | 792 | info[0] = ROAR_NET2HOST16(info[0]); |
---|
| 793 | info[1] = ROAR_NET2HOST16(info[1]); |
---|
| 794 | |
---|
[0] | 795 | if ( info[0] == ROAR_OT_CLIENT ) { |
---|
| 796 | clients_delete(info[1]); |
---|
| 797 | } else if ( info[0] == ROAR_OT_STREAM ) { |
---|
[2952] | 798 | if ( streams_get_flag(info[1], ROAR_FLAG_IMMUTABLE) == 1 ) |
---|
| 799 | return -1; |
---|
| 800 | |
---|
[0] | 801 | streams_delete(info[1]); |
---|
[1111] | 802 | } else if ( info[0] == ROAR_OT_SOURCE ) { |
---|
[2952] | 803 | if ( streams_get_flag(info[1], ROAR_FLAG_IMMUTABLE) == 1 ) |
---|
| 804 | return -1; |
---|
| 805 | |
---|
[1111] | 806 | if ( streams_get_flag(info[1], ROAR_FLAG_SOURCE) == 1 ) { |
---|
| 807 | streams_delete(info[1]); |
---|
| 808 | } else { |
---|
| 809 | return -1; |
---|
| 810 | } |
---|
[0] | 811 | } else { |
---|
| 812 | return -1; |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | mes->cmd = ROAR_CMD_OK; |
---|
| 816 | mes->datalen = 0; |
---|
| 817 | |
---|
| 818 | return 0; |
---|
| 819 | } |
---|
| 820 | |
---|
[768] | 821 | int req_on_attach (int client, struct roar_message * mes, char * data) { |
---|
[769] | 822 | uint16_t * info = (uint16_t *) mes->data; |
---|
| 823 | |
---|
| 824 | if ( mes->datalen < 6 ) |
---|
| 825 | return -1; |
---|
| 826 | |
---|
| 827 | info[0] = ROAR_NET2HOST16(info[0]); |
---|
| 828 | info[1] = ROAR_NET2HOST16(info[1]); |
---|
| 829 | info[2] = ROAR_NET2HOST16(info[2]); |
---|
| 830 | |
---|
| 831 | if ( info[0] != 0 ) |
---|
| 832 | return -1; |
---|
| 833 | |
---|
| 834 | if ( info[1] == ROAR_ATTACH_SIMPLE ) { |
---|
| 835 | if ( client_stream_move(info[2], mes->stream) == -1 ) |
---|
| 836 | return -1; |
---|
| 837 | } else { |
---|
| 838 | return -1; |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | mes->cmd = ROAR_CMD_OK; |
---|
| 842 | mes->datalen = 0; |
---|
| 843 | |
---|
| 844 | return 0; |
---|
[768] | 845 | } |
---|
| 846 | |
---|
[17] | 847 | int req_on_set_vol (int client, struct roar_message * mes, char * data) { |
---|
[3530] | 848 | struct roar_stream_server * s; |
---|
[17] | 849 | uint16_t * info = (uint16_t *) mes->data; |
---|
[3530] | 850 | uint16_t version; |
---|
| 851 | uint16_t scale = 65535; |
---|
[17] | 852 | int stream; |
---|
| 853 | int i; |
---|
| 854 | int chans; |
---|
| 855 | |
---|
| 856 | ROAR_DBG("req_on_set_vol(*) = ?"); |
---|
| 857 | ROAR_DBG("req_on_set_vol(*): mes->datalen=%i", mes->datalen); |
---|
| 858 | |
---|
| 859 | if ( mes->datalen < (4*2) ) |
---|
| 860 | return -1; |
---|
| 861 | |
---|
[3530] | 862 | version = ROAR_NET2HOST16(info[0]); |
---|
| 863 | ROAR_DBG("req_on_set_vol(*): version=%i", (int)version); |
---|
[17] | 864 | |
---|
[3530] | 865 | switch (version) { |
---|
| 866 | case 0: |
---|
| 867 | stream = ROAR_NET2HOST16(info[1]); |
---|
| 868 | break; |
---|
| 869 | case 1: |
---|
| 870 | stream = mes->stream; |
---|
| 871 | scale = ROAR_NET2HOST16(info[1]); |
---|
| 872 | break; |
---|
| 873 | default: |
---|
| 874 | return -1; |
---|
| 875 | break; |
---|
| 876 | } |
---|
[17] | 877 | ROAR_DBG("req_on_set_vol(*): stream=%i", stream); |
---|
| 878 | |
---|
[3561] | 879 | if ( scale == 0 ) |
---|
| 880 | return -1; |
---|
| 881 | |
---|
[17] | 882 | // TODO: change this code. |
---|
| 883 | // we should not directly change the stream object but use some stream_*()-func |
---|
| 884 | // for that job. |
---|
| 885 | |
---|
| 886 | if ( stream < 0 || stream >= ROAR_STREAMS_MAX ) |
---|
| 887 | return -1; |
---|
| 888 | |
---|
| 889 | s = g_streams[stream]; |
---|
| 890 | |
---|
| 891 | if ( s == NULL ) |
---|
| 892 | return -1; |
---|
| 893 | |
---|
| 894 | ROAR_DBG("req_on_set_vol(*): s=%p", s); |
---|
| 895 | |
---|
[252] | 896 | info[2] = ROAR_NET2HOST16(info[2]); |
---|
| 897 | |
---|
[17] | 898 | if ( info[2] == ROAR_SET_VOL_ALL ) { |
---|
| 899 | chans = (mes->datalen/2) - 3; |
---|
| 900 | ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ALL, channes=%i", chans); |
---|
| 901 | |
---|
| 902 | if ( chans >= ROAR_MAX_CHANNELS ) |
---|
| 903 | return -1; |
---|
| 904 | |
---|
[18] | 905 | ROAR_DBG("req_on_set_vol(*): mixer at %p", s->mixer.mixer); |
---|
| 906 | |
---|
[17] | 907 | for (i = 0; i < chans; i++) { |
---|
[252] | 908 | s->mixer.mixer[i] = ROAR_NET2HOST16(info[i+3]); |
---|
| 909 | ROAR_DBG("req_on_set_vol(*): channel %i: %i", i, ROAR_NET2HOST16(info[i+3])); |
---|
[17] | 910 | } |
---|
| 911 | |
---|
[3530] | 912 | s->mixer.scale = scale; |
---|
| 913 | |
---|
[17] | 914 | ROAR_DBG("req_on_set_vol(*): mixer changed!"); |
---|
| 915 | |
---|
| 916 | } else if ( info[2] == ROAR_SET_VOL_ONE ) { |
---|
| 917 | ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ONE"); |
---|
[252] | 918 | if ( ROAR_NET2HOST16(info[3]) >= ROAR_MAX_CHANNELS ) |
---|
[17] | 919 | return -1; |
---|
| 920 | |
---|
[252] | 921 | s->mixer.mixer[ROAR_NET2HOST16(info[3])] = ROAR_NET2HOST16(info[4]); |
---|
[3530] | 922 | |
---|
| 923 | s->mixer.scale = scale; |
---|
[17] | 924 | } else { |
---|
| 925 | return -1; |
---|
| 926 | } |
---|
| 927 | |
---|
[1590] | 928 | if ( streams_set_mixer(stream) == -1 ) |
---|
| 929 | return -1; |
---|
| 930 | |
---|
[17] | 931 | mes->cmd = ROAR_CMD_OK; |
---|
| 932 | mes->datalen = 0; |
---|
| 933 | |
---|
| 934 | return 0; |
---|
| 935 | } |
---|
[0] | 936 | |
---|
[23] | 937 | int req_on_get_vol (int client, struct roar_message * mes, char * data) { |
---|
| 938 | uint16_t * info = (uint16_t *) mes->data; |
---|
[3529] | 939 | uint16_t version = -1; |
---|
[23] | 940 | int stream; |
---|
| 941 | struct roar_stream_server * s; |
---|
| 942 | int i; |
---|
| 943 | int chans; |
---|
| 944 | |
---|
| 945 | ROAR_DBG("req_on_get_vol(*) = ?"); |
---|
| 946 | ROAR_DBG("req_on_get_vol(*): mes->datalen=%i", mes->datalen); |
---|
| 947 | |
---|
[3529] | 948 | if ( mes->datalen < 2 ) { |
---|
[23] | 949 | return -1; |
---|
[3529] | 950 | } |
---|
| 951 | |
---|
| 952 | version = ROAR_NET2HOST16(info[0]); |
---|
| 953 | |
---|
| 954 | switch (version) { |
---|
| 955 | case 0: |
---|
| 956 | if ( mes->datalen < (2*2) ) |
---|
| 957 | return -1; |
---|
[23] | 958 | |
---|
[3529] | 959 | stream = ROAR_NET2HOST16(info[1]); |
---|
| 960 | break; |
---|
| 961 | case 1: |
---|
| 962 | stream = mes->stream; |
---|
| 963 | break; |
---|
| 964 | default: |
---|
| 965 | return -1; |
---|
| 966 | break; |
---|
| 967 | } |
---|
[23] | 968 | |
---|
| 969 | ROAR_DBG("req_on_get_vol(*): stream=%i", stream); |
---|
| 970 | |
---|
| 971 | // TODO: change this code. |
---|
| 972 | // we should not directly change the stream object but use some stream_*()-func |
---|
| 973 | // for that job. |
---|
| 974 | |
---|
| 975 | if ( stream < 0 || stream >= ROAR_STREAMS_MAX ) |
---|
| 976 | return -1; |
---|
| 977 | |
---|
| 978 | s = g_streams[stream]; |
---|
| 979 | |
---|
| 980 | if ( s == NULL ) |
---|
| 981 | return -1; |
---|
| 982 | |
---|
| 983 | ROAR_DBG("req_on_get_vol(*): s=%p", s); |
---|
| 984 | |
---|
| 985 | // ok, we have everything |
---|
| 986 | |
---|
[3529] | 987 | info[0] = ROAR_HOST2NET16(version); |
---|
| 988 | |
---|
| 989 | switch (version) { |
---|
| 990 | case 0: |
---|
| 991 | info[1] = ROAR_HOST2NET16(chans = ROAR_STREAM(s)->info.channels); |
---|
| 992 | |
---|
| 993 | for (i = 0; i < chans; i++) |
---|
| 994 | info[2+i] = ROAR_HOST2NET16(s->mixer.mixer[i]); |
---|
[23] | 995 | |
---|
[3529] | 996 | mes->datalen = (2 + chans)*2; |
---|
| 997 | break; |
---|
| 998 | case 1: |
---|
| 999 | info[1] = ROAR_HOST2NET16(chans = ROAR_STREAM(s)->info.channels); |
---|
| 1000 | info[2] = ROAR_HOST2NET16(s->mixer.scale); |
---|
| 1001 | info[3] = ROAR_HOST2NET16(s->mixer.rpg_mul); |
---|
| 1002 | info[4] = ROAR_HOST2NET16(s->mixer.rpg_div); |
---|
[23] | 1003 | |
---|
[3529] | 1004 | for (i = 0; i < chans; i++) |
---|
| 1005 | info[5+i] = ROAR_HOST2NET16(s->mixer.mixer[i]); |
---|
| 1006 | |
---|
| 1007 | mes->datalen = (5 + chans)*2; |
---|
| 1008 | break; |
---|
| 1009 | default: |
---|
| 1010 | return -1; |
---|
| 1011 | break; |
---|
| 1012 | } |
---|
| 1013 | |
---|
[23] | 1014 | mes->cmd = ROAR_CMD_OK; |
---|
| 1015 | |
---|
| 1016 | return 0; |
---|
| 1017 | } |
---|
| 1018 | |
---|
[0] | 1019 | int req_on_add_data (int client, struct roar_message * mes, char * data) { |
---|
| 1020 | struct roar_buffer * b; |
---|
| 1021 | char * buf; |
---|
| 1022 | |
---|
| 1023 | if ( roar_buffer_new(&b, mes->datalen) == -1 ) { |
---|
| 1024 | ROAR_ERR("req_on_add_data(*): Can not alloc buffer space!"); |
---|
| 1025 | ROAR_DBG("req_on_add_data(*) = -1"); |
---|
| 1026 | return -1; |
---|
| 1027 | } |
---|
| 1028 | |
---|
| 1029 | roar_buffer_get_data(b, (void **)&buf); |
---|
| 1030 | |
---|
| 1031 | if ( data == NULL ) { |
---|
| 1032 | memcpy(buf, mes->data, mes->datalen); |
---|
| 1033 | } else { |
---|
| 1034 | memcpy(buf, data, mes->datalen); |
---|
| 1035 | } |
---|
| 1036 | |
---|
| 1037 | if ( stream_add_buffer(mes->stream, b) == -1 ) { |
---|
| 1038 | roar_buffer_free(b); |
---|
| 1039 | return -1; |
---|
| 1040 | } |
---|
| 1041 | |
---|
[498] | 1042 | mes->cmd = ROAR_CMD_OK_STOP; |
---|
[0] | 1043 | mes->datalen = 0; |
---|
| 1044 | |
---|
| 1045 | return 0; |
---|
| 1046 | } |
---|
| 1047 | |
---|
[3574] | 1048 | int req_on_beep (int client, struct roar_message * mes, char * data) { |
---|
[3575] | 1049 | struct roar_beep bs; |
---|
| 1050 | int16_t * info = (int16_t*)mes->data; |
---|
| 1051 | int stream; |
---|
| 1052 | |
---|
| 1053 | memset(&bs, 0, sizeof(bs)); |
---|
| 1054 | |
---|
| 1055 | if ( mes->datalen > 0 ) { |
---|
| 1056 | if ( mes->datalen < 2 ) |
---|
| 1057 | return -1; |
---|
| 1058 | |
---|
| 1059 | if ( ROAR_NET2HOST16(info[0]) != 0 ) /* version */ |
---|
| 1060 | return -1; |
---|
| 1061 | |
---|
| 1062 | if ( mes->datalen != 8*2 ) |
---|
| 1063 | return -1; |
---|
| 1064 | |
---|
| 1065 | bs.vol = ROAR_NET2HOST16(info[1]); |
---|
| 1066 | bs.time = ROAR_NET2HOST16(info[2]); |
---|
| 1067 | bs.freq = ROAR_NET2HOST16(info[3]); |
---|
| 1068 | bs.type = ROAR_NET2HOST16(info[4]); |
---|
| 1069 | bs.x = ROAR_NET2HOST16(info[5]); |
---|
| 1070 | bs.y = ROAR_NET2HOST16(info[6]); |
---|
| 1071 | bs.z = ROAR_NET2HOST16(info[7]); |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | if ( (stream = beep_start(client, &bs)) == -1 ) |
---|
| 1075 | return -1; |
---|
| 1076 | |
---|
| 1077 | mes->stream = stream; |
---|
| 1078 | mes->cmd = ROAR_CMD_OK_STOP; |
---|
| 1079 | mes->datalen = 0; |
---|
| 1080 | |
---|
| 1081 | return 0; |
---|
[3574] | 1082 | } |
---|
| 1083 | |
---|
[0] | 1084 | //ll |
---|