source: roaraudio/roard/req.c @ 2630:909519a92c03

Last change on this file since 2630:909519a92c03 was 2630:909519a92c03, checked in by phi, 15 years ago

stream para include stream state

File size: 19.9 KB
Line 
1//req.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27int req_on_noop        (int client, struct roar_message * mes, char * data) {
28 mes->cmd     = ROAR_CMD_OK;
29 mes->datalen = 0;
30 return 0;
31}
32
33int req_on_identify    (int client, struct roar_message * mes, char * data) {
34 struct roar_client * c;
35 int max_len;
36
37 if ( mes->datalen < 1 )
38  return -1;
39
40 clients_get(client, &c);
41
42 if ( mes->data[0] == 1 ) {
43  if ( c->pid == -1 ) {
44   c->pid       = ROAR_NET2HOST32(*(uint32_t*)((mes->data)+1));
45   ROAR_DBG("req_on_identify(): new PID: c->pid = %i", c->pid);
46  }
47
48  ROAR_DBG("req_on_identify(): final PID: c->pid = %i", c->pid);
49
50  max_len = (mes->datalen - 5) < (ROAR_BUFFER_NAME-1) ? (mes->datalen - 5) : (ROAR_BUFFER_NAME-1);
51
52  strncpy(c->name, mes->data + 5, max_len);
53  c->name[max_len] = 0;
54
55  mes->cmd     = ROAR_CMD_OK;
56  mes->datalen = 0;
57
58  ROAR_DBG("req_on_identify(*): client=%i, pid=%i", client, c->pid);
59  ROAR_DBG("req_on_identify(*) = 0");
60  return 0;
61 }
62
63 return -1;
64}
65
66int req_on_auth        (int client, struct roar_message * mes, char * data) {
67 // TODO: add code to support some auth.
68 mes->cmd     = ROAR_CMD_OK;
69 mes->datalen = 0;
70 return 0;
71}
72
73
74int req_on_whoami      (int client, struct roar_message * mes, char * data) {
75 mes->cmd     = ROAR_CMD_OK;
76 mes->datalen = 1;
77 mes->data[0] = client;
78 return 0;
79}
80
81
82int req_on_new_stream  (int client, struct roar_message * mes, char * data) {
83 int stream;
84 struct roar_stream * s;
85 struct roar_stream * source_stream;
86 struct roar_audio_info * info;
87 struct roar_audio_info * source_info;
88
89 ROAR_DBG("req_on_new_stream(client=%i, ...): creating stream...", client);
90 if ((stream = streams_new()) == -1 )
91  return -1;
92
93 ROAR_DBG("req_on_new_stream(client=%i, ...): getting stream...", client);
94 if ( streams_get(stream, (struct roar_stream_server **)&s) == -1 ) {
95  streams_delete(stream);
96  return -1;
97 }
98
99 ROAR_DBG("req_on_new_stream(client=%i, ...): set client of stream...", client);
100 if ( client_stream_add(client, stream) == -1 ) {
101  streams_delete(stream);
102  return -1;
103 }
104
105 ROAR_DBG("req_on_new_stream(client=%i, ...): loading stream from message...", client);
106 if ( roar_stream_m2s(s, mes) == -1 ) {
107  streams_delete(stream);
108  return -1;
109 }
110
111 ROAR_DBG("req_on_new_stream(client=%i, ...): setting id and codec of stream...", client);
112 ROAR_STREAM(s)->id = stream; // roar_stream_m2s() resets this
113 ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM(s)->info.codec;
114
115 ROAR_DBG("req_on_new_stream(client=%i, ...): setting direction stream...", client);
116 // int streams_set_dir    (int id, int dir, int defaults)
117 if ( streams_set_dir(stream, ROAR_STREAM(s)->dir, 1) == -1 ) {
118  streams_delete(stream);
119  return -1;
120 }
121
122 ROAR_DBG("req_on_new_stream(client=%i, ...): setting up direction specific stream settings...", client);
123 switch (ROAR_STREAM(s)->dir) {
124  case ROAR_DIR_LIGHT_IN:
125  case ROAR_DIR_LIGHT_OUT:
126#ifndef ROAR_WITHOUT_DCOMP_LIGHT
127    info = &(ROAR_STREAM(s)->info);
128
129    info->channels = 0;
130    info->bits     = 0;
131    info->rate     = 0;
132#else
133    streams_delete(stream);
134    return -1;
135#endif
136
137   break;
138  case ROAR_DIR_MIDI_IN:
139  case ROAR_DIR_MIDI_OUT:
140#ifndef ROAR_WITHOUT_DCOMP_MIDI
141    info = &(ROAR_STREAM(s)->info);
142
143    info->channels = ROAR_MIDI_CHANNELS_DEFAULT;
144    info->bits     = ROAR_MIDI_BITS;
145    info->rate     = 0;
146#else
147    streams_delete(stream);
148    return -1;
149#endif
150
151   break;
152
153  case ROAR_DIR_RAW_IN:
154#ifndef ROAR_WITHOUT_DCOMP_RAW
155    if ( ROAR_STREAM(s)->pos_rel_id == -1     ||
156         ROAR_STREAM(s)->pos_rel_id == stream ||
157         streams_get_dir(ROAR_STREAM(s)->pos_rel_id) != ROAR_DIR_RAW_OUT
158       ) {
159     ROAR_STREAM(s)->pos_rel_id = -1; // force this here as it will try to delete itself while deleting
160                                      // in case rel_id == stream
161     streams_delete(stream);
162     return -1;
163    }
164#else
165  case ROAR_DIR_RAW_OUT:
166    streams_delete(stream);
167    return -1;
168#endif
169
170   break;
171  case ROAR_DIR_THRU:
172
173    if ( ROAR_STREAM(s)->pos_rel_id == -1 || ROAR_STREAM(s)->pos_rel_id == stream ) {
174     ROAR_STREAM(s)->pos_rel_id = -1; // force this here as it will try to delete itself while deleting
175                                      // in case rel_id == stream
176     streams_delete(stream);
177     return -1;
178    }
179
180    if ( streams_get(ROAR_STREAM(s)->pos_rel_id, (struct roar_stream_server **)&source_stream) == -1 ) {
181     streams_delete(stream);
182     return -1;
183    }
184
185    info        = &(ROAR_STREAM(s)->info);
186    source_info = &(ROAR_STREAM(source_stream)->info);
187
188    info->channels = source_info->channels;
189    info->bits     = source_info->bits;
190    info->rate     = source_info->rate;
191    info->codec    = source_info->codec;
192    ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM_SERVER(source_stream)->codec_orgi;
193
194   break;
195 }
196
197 ROAR_DBG("req_on_new_stream(client=%i, ...): returning (OK)...", client);
198
199 mes->cmd     = ROAR_CMD_OK;
200 mes->stream  = stream;
201 mes->datalen = 0;
202
203 return 0;
204}
205
206int req_on_exec_stream (int client, struct roar_message * mes, char * data) {
207 int r;
208
209 ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): execing stream", client, mes->stream);
210
211 if ( (r = client_stream_exec(client, mes->stream)) == -1 )
212  return -1;
213
214 ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): returning (OK)...", client, mes->stream);
215 mes->cmd     = ROAR_CMD_OK;
216 mes->datalen = 0;
217
218 return 0;
219}
220
221int req_on_con_stream  (int client, struct roar_message * mes, char * data) {
222 char   host[80] = {0};
223 int    port = 0;
224 int    type;
225 int    fh;
226 int    len;
227
228 if ( mes->datalen < 4 )
229  return -1;
230
231 if ( *(mes->data) != 0 )
232  return -1;
233
234 if ( mes->datalen > 80 ) // we do not support long messages here
235  return -1;
236
237 type = (unsigned)mes->data[1];
238 port = ROAR_NET2HOST16(((uint16_t*)mes->data)[1]);
239
240 len = mes->datalen - 4;
241
242 strncpy(host, &(mes->data[4]), len);
243 host[len] = 0;
244
245 if ( type > ROAR_SOCKET_TYPE_MAX )
246  return -1;
247
248 if ( type == ROAR_SOCKET_TYPE_FILE ) // disabled because of security resons
249  return -1;
250
251 if ( type == ROAR_SOCKET_TYPE_FORK ) // why should we connect to ourself?
252  return -1;
253
254 ROAR_DBG("req_on_con_stream(*): CONNECT(type=%i, host='%s', port=%i)", type, host, port);
255
256 if ( (fh = roar_socket_open(ROAR_SOCKET_MODE_CONNECT, type, host, port)) == -1 )
257  return -1;
258
259 if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) {
260  close(fh);
261  return 1;
262 }
263
264 mes->datalen = 0;
265 mes->cmd     = ROAR_CMD_OK;
266
267 return 0;
268}
269
270int req_on_passfh      (int client, struct roar_message * mes, char * data) {
271 int fh;
272 int sock = clients_get_fh(client);
273
274 if ( (fh = roar_socket_recv_fh(sock, NULL, NULL)) == -1 )
275  return -1;
276
277 if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) {
278  close(fh);
279  return 1;
280 }
281
282
283 mes->datalen = 0;
284 mes->cmd     = ROAR_CMD_OK;
285
286 return 0;
287}
288
289#ifdef ROAR_SUPPORT_META
290int req_on_set_meta    (int client, struct roar_message * mes, char * data) {
291 int type;
292 int mode;
293 int namelen, vallen;
294 char   val[255+1];
295 char   name[ROAR_META_MAX_NAMELEN+1];
296
297 if ( mes->datalen < 3 )
298  return -1;
299
300 if ( mes->data[0] != 0 ) // version
301  return -1;
302
303 mode = (unsigned) mes->data[1];
304 type = (unsigned) mes->data[2];
305
306 ROAR_DBG("req_on_set_meta(*): mode=%i, type=%i", mode, type);
307
308 if ( mode == ROAR_META_MODE_CLEAR ) {
309  stream_meta_clear(mes->stream);
310  mes->datalen = 0;
311  mes->cmd     = ROAR_CMD_OK;
312  return 0;
313 } else if ( mode == ROAR_META_MODE_DELETE ) { // unsuppoerted at the moment
314  return -1;
315 } else if ( mode == ROAR_META_MODE_FINALIZE ) {
316  stream_meta_finalize(mes->stream);
317  mes->datalen = 0;
318  mes->cmd     = ROAR_CMD_OK;
319  return 0;
320 } else if ( mode == ROAR_META_MODE_SET || mode == ROAR_META_MODE_ADD ) {
321  if ( mes->datalen < 5 )
322   return -1;
323
324  namelen = (unsigned) mes->data[3];
325  vallen  = (unsigned) mes->data[4];
326
327  ROAR_DBG("req_on_set_meta(*): namelen=%i, vallen=%i", namelen, vallen);
328
329  if ( mes->datalen < (5 + namelen + vallen) )
330   return -1;
331
332  if ( namelen > ROAR_META_MAX_NAMELEN )
333   return -1;
334
335  strncpy(name, &(mes->data[5]), namelen);
336  name[namelen] = 0;
337
338  if ( vallen > 255 )
339   return -1;
340
341  strncpy(val, &(mes->data[5+namelen]), vallen);
342  val[vallen] = 0;
343
344  if ( mode == ROAR_META_MODE_SET ) {
345   if ( stream_meta_set(mes->stream, type, name, val) == -1 )
346    return -1;
347  } else {
348   if ( stream_meta_add(mes->stream, type, name, val) == -1 )
349    return -1;
350  }
351
352  mes->datalen = 0;
353  mes->cmd     = ROAR_CMD_OK;
354  return 0;
355 } else { // unknown mode!
356  return -1;
357 }
358
359 return -1;
360}
361
362int req_on_get_meta    (int client, struct roar_message * mes, char * data) {
363 int vallen;
364 int type;
365 char val[LIBROAR_BUFFER_MSGDATA-1];
366
367 if ( mes->datalen != 2 )
368  return -1;
369
370 if ( mes->data[0] != 0 ) // version
371  return -1;
372
373 type = (unsigned) mes->data[1];
374
375 if ( stream_meta_get(mes->stream, type, NULL, val, LIBROAR_BUFFER_MSGDATA-2) == -1 )
376  return -1;
377
378 vallen = strlen(val);
379
380 mes->cmd     = ROAR_CMD_OK;
381 mes->datalen = 2 + vallen;
382
383 mes->data[0] = 0;
384 mes->data[1] = (unsigned char) vallen;
385
386 val[vallen] = 0;
387
388 strncpy(&(mes->data[2]), val, vallen+1);
389
390 return 0;
391}
392
393int req_on_list_meta   (int client, struct roar_message * mes, char * data) {
394 int i;
395 int len = 0;
396 int types[ROAR_META_MAX_PER_STREAM];
397
398 if ( mes->datalen != 1 )
399  return -1;
400
401 if ( mes->data[0] != 0 ) // version
402  return -1;
403
404 if ( (len = stream_meta_list(mes->stream, types, ROAR_META_MAX_PER_STREAM)) == -1 )
405  return -1;
406
407 mes->cmd     = ROAR_CMD_OK;
408 mes->datalen = 1 + len;
409 mes->data[0] = 0;
410
411 for (i = 0; i < len; i++)
412  mes->data[i+1] = types[i];
413
414 return 0;
415}
416#endif
417
418int req_on_server_oinfo    (int client, struct roar_message * mes, char * data) {
419 struct roar_stream s;
420//ROAR_DIR_OUTPUT
421
422 memset(&s, 0, sizeof(struct roar_stream));
423
424 s.dir           = ROAR_DIR_MIXING;
425 s.pos_rel_id    = -1;
426 s.info.rate     = g_sa->rate;
427 s.info.bits     = g_sa->bits;
428 s.info.channels = g_sa->channels;
429 s.info.codec    = g_sa->codec;
430 s.pos           = g_pos;
431
432 if ( roar_stream_s2m(&s, mes) == -1 )
433  return -1;
434
435 mes->cmd = ROAR_CMD_OK;
436
437 return 0;
438}
439
440
441int req_on_get_standby (int client, struct roar_message * mes, char * data) {
442 mes->cmd = ROAR_CMD_OK;
443 mes->datalen = 2;
444
445 *((uint16_t*)mes->data) = ROAR_HOST2NET16((unsigned) g_standby);
446
447 return 0;
448}
449
450int req_on_set_standby (int client, struct roar_message * mes, char * data) {
451 if ( mes->datalen != 2 )
452  return -1;
453
454 g_standby = ROAR_NET2HOST16(*((uint16_t*)mes->data));
455
456 mes->cmd     = ROAR_CMD_OK;
457 mes->datalen = 0;
458
459 return 0;
460}
461
462int req_on_exit      (int client, struct roar_message * mes, char * data) {
463 int term = 0;
464
465 if ( mes->datalen == 1 )
466  term = mes->data[0];
467
468 mes->cmd     = ROAR_CMD_OK;
469 mes->datalen = 0;
470
471 ROAR_DBG("req_on_exit(*): term=%i", term);
472
473 if ( term ) {
474  cleanup_listen_socket(1);
475 } else {
476  alive = 0;
477 }
478
479 return 0;
480}
481
482int req_on_list_clients(int client, struct roar_message * mes, char * data) {
483 unsigned char filter, cmp;
484 uint32_t id;
485 int clients[ROAR_CLIENTS_MAX];
486 int i, c = 0;
487
488 if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 )
489  return -1;
490
491 // TODO: add code to support filter
492 if ( filter != ROAR_CTL_FILTER_ANY )
493  return -1;
494
495 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
496  if ( g_clients[i] != NULL ) {
497   clients[c++] = i;
498  }
499 }
500
501 roar_ctl_ia2m(mes, clients, c);
502
503 mes->cmd = ROAR_CMD_OK;
504
505 return 0;
506}
507int req_on_list_streams(int client, struct roar_message * mes, char * data) {
508 unsigned char filter, cmp;
509 uint32_t id;
510 int streams[ROAR_STREAMS_MAX];
511 int i, c = 0;
512
513 if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 )
514  return -1;
515
516 // TODO: add code to support filter
517 if ( filter != ROAR_CTL_FILTER_ANY )
518  return -1;
519
520 for (i = 0; i < ROAR_STREAMS_MAX; i++) {
521  if ( g_streams[i] != NULL ) {
522   streams[c++] = i;
523  }
524 }
525
526 roar_ctl_ia2m(mes, streams, c);
527
528 mes->cmd = ROAR_CMD_OK;
529
530 return 0;
531}
532
533int req_on_get_client  (int client, struct roar_message * mes, char * data) {
534 struct roar_client * c;
535
536 if ( mes->datalen != 1 )
537  return -1;
538
539 if ( clients_get(mes->data[0], &c) == -1 )
540  return -1;
541
542 mes->cmd = ROAR_CMD_OK;
543
544 return roar_ctl_c2m(mes, c);
545}
546
547int req_on_get_stream  (int client, struct roar_message * mes, char * data) {
548 struct roar_stream_server * s;
549
550 if ( mes->datalen != 1 )
551  return -1;
552
553 if ( streams_get(mes->data[0], &s) == -1 )
554  return -1;
555
556 mes->cmd = ROAR_CMD_OK;
557 mes->stream = mes->data[0];
558
559 return roar_stream_s2m(ROAR_STREAM(s), mes);
560}
561
562int req_on_get_stream_para (int client, struct roar_message * mes, char * data) {
563 struct roar_stream * s;
564 struct roar_stream_server * ss;
565 struct roar_audio_info * audio_info;
566 uint16_t * d = (uint16_t *) mes->data;
567 int i;
568 char * str;
569
570 if ( mes->datalen != 4 )
571  return -1;
572
573 for (i = 0; i < mes->datalen/2; i++) {
574  d[i] = ROAR_NET2HOST16(d[i]);
575 }
576
577 if ( d[0] != 0 ) {
578  ROAR_WARN("req_on_get_stream_para(*): unsupported command version: %i, %i", d[0], d[1]);
579  return -1;
580 }
581
582 switch (d[1]) {
583  case ROAR_STREAM_PARA_INFO:
584    if ( streams_get(mes->stream, &ss) == -1 ) {
585     ROAR_WARN("req_on_get_stream_para(*): request on non existing (or other error?) stream %i", mes->stream);
586     return -1;
587    }
588
589    if ( streams_calc_delay(mes->stream) == -1 ) {
590     ROAR_WARN("req_on_get_stream_para(*): can not calc delay for stream %i", mes->stream);
591    }
592
593    s = ROAR_STREAM(ss);
594
595    audio_info = &(s->info);
596
597    mes->datalen = 2*9;
598
599    d[2] = ROAR_OUTPUT_CALC_OUTBUFSIZE(audio_info);
600    d[3] = ss->pre_underruns;
601    d[4] = ss->post_underruns;
602    d[5] = ss->codec_orgi;
603    d[6] = ss->flags | (ss->primary ? ROAR_FLAG_PRIMARY : 0) | (ss->driver_id != -1 ? ROAR_FLAG_OUTPUT : 0);
604    d[7] = ss->delay/1000;
605    d[8] = ss->state;
606
607    ROAR_DBG("req_on_get_stream_para(*): ss->driver_id=%i", ss->driver_id);
608
609    ROAR_DBG("req_on_get_stream_para(*): delay=%i, send delay=%i", ss->delay, d[7]);
610
611    for (i = 0; i < mes->datalen/2; i++) {
612     d[i] = ROAR_HOST2NET16(d[i]);
613    }
614
615    mes->pos = s->pos;
616   break;
617
618  case ROAR_STREAM_PARA_NAME:
619   str = streams_get_name(mes->stream);
620
621   if ( str == NULL )
622    return -1;
623
624    mes->datalen = 4 + strlen(str);
625
626    if ( mes->datalen > LIBROAR_BUFFER_MSGDATA )
627     return -1;
628
629    strncpy(((char*)&(mes->data))+4, str, mes->datalen);
630
631    d[0] = ROAR_HOST2NET16(d[0]);
632    d[1] = ROAR_HOST2NET16(d[1]);
633   break;
634
635  default:
636    ROAR_WARN("req_on_get_stream_para(*): unsupported command: %i", d[1]);
637    return -1;
638 }
639
640 mes->cmd = ROAR_CMD_OK;
641 return 0;
642}
643
644int req_on_set_stream_para (int client, struct roar_message * mes, char * data) {
645 uint16_t * d = (uint16_t *) mes->data;
646 int i;
647
648 if ( mes->datalen != 8 )
649  return -1;
650
651 for (i = 0; i < mes->datalen/2; i++) {
652  d[i] = ROAR_NET2HOST16(d[i]);
653 }
654
655 if ( d[0] != 0 || d[1] != ROAR_STREAM_PARA_FLAGS ) {
656  ROAR_WARN("req_on_set_stream_para(*): unsupported command version: %i, %i", d[0], d[1]);
657  return -1;
658 }
659
660 mes->cmd     = ROAR_CMD_OK;
661 mes->datalen = 0;
662
663 ROAR_DBG("req_on_set_stream_para(*): request seems to be valid");
664
665 if ( d[2] == ROAR_RESET_FLAG ) {
666  return streams_reset_flag(mes->stream, d[3]);
667 } else {
668  return streams_set_flag(mes->stream, d[3]);
669 }
670
671 return -1;
672}
673
674int req_on_kick (int client, struct roar_message * mes, char * data) {
675 uint16_t * info = (uint16_t *) mes->data;
676
677 if ( mes->datalen != 4 )
678  return -1;
679
680 info[0] = ROAR_NET2HOST16(info[0]);
681 info[1] = ROAR_NET2HOST16(info[1]);
682
683 if ( info[0] == ROAR_OT_CLIENT ) {
684  clients_delete(info[1]);
685 } else if ( info[0] == ROAR_OT_STREAM ) {
686  streams_delete(info[1]);
687 } else if ( info[0] == ROAR_OT_SOURCE ) {
688  if ( streams_get_flag(info[1], ROAR_FLAG_SOURCE) == 1 ) {
689   streams_delete(info[1]);
690  } else {
691   return -1;
692  }
693 } else {
694  return -1;
695 }
696
697 mes->cmd     = ROAR_CMD_OK;
698 mes->datalen = 0;
699
700 return 0;
701}
702
703int req_on_attach      (int client, struct roar_message * mes, char * data) {
704 uint16_t * info = (uint16_t *) mes->data;
705
706 if ( mes->datalen < 6 )
707  return -1;
708
709 info[0] = ROAR_NET2HOST16(info[0]);
710 info[1] = ROAR_NET2HOST16(info[1]);
711 info[2] = ROAR_NET2HOST16(info[2]);
712
713 if ( info[0] != 0 )
714  return -1;
715
716 if ( info[1] == ROAR_ATTACH_SIMPLE ) {
717  if ( client_stream_move(info[2], mes->stream) == -1 )
718   return -1;
719 } else {
720  return -1;
721 }
722
723 mes->cmd     = ROAR_CMD_OK;
724 mes->datalen = 0;
725
726 return 0;
727}
728
729int req_on_set_vol (int client, struct roar_message * mes, char * data) {
730 uint16_t * info = (uint16_t *) mes->data;
731 int stream;
732 struct roar_stream_server * s;
733 int i;
734 int chans;
735
736 ROAR_DBG("req_on_set_vol(*) = ?");
737 ROAR_DBG("req_on_set_vol(*): mes->datalen=%i", mes->datalen);
738
739 if ( mes->datalen < (4*2) )
740  return -1;
741
742 if ( info[0] != 0 ) // version
743  return -1;
744
745 stream = ROAR_NET2HOST16(info[1]);
746 ROAR_DBG("req_on_set_vol(*): stream=%i", stream);
747
748 // TODO: change this code.
749 //       we should not directly change the stream object but use some stream_*()-func
750 //       for that job.
751
752 if ( stream < 0 || stream >= ROAR_STREAMS_MAX )
753  return -1;
754
755 s = g_streams[stream];
756
757 if ( s == NULL )
758  return -1;
759
760 ROAR_DBG("req_on_set_vol(*): s=%p", s);
761
762 info[2] = ROAR_NET2HOST16(info[2]);
763
764 if ( info[2] == ROAR_SET_VOL_ALL ) {
765  chans = (mes->datalen/2) - 3;
766  ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ALL, channes=%i", chans);
767
768  if ( chans >= ROAR_MAX_CHANNELS )
769   return -1;
770
771  ROAR_DBG("req_on_set_vol(*): mixer at %p", s->mixer.mixer);
772
773  for (i = 0; i < chans; i++) {
774   s->mixer.mixer[i] = ROAR_NET2HOST16(info[i+3]);
775   ROAR_DBG("req_on_set_vol(*): channel %i: %i", i, ROAR_NET2HOST16(info[i+3]));
776  }
777
778  ROAR_DBG("req_on_set_vol(*): mixer changed!");
779
780 } else if ( info[2] == ROAR_SET_VOL_ONE ) {
781  ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ONE");
782  if ( ROAR_NET2HOST16(info[3]) >= ROAR_MAX_CHANNELS )
783   return -1;
784
785  s->mixer.mixer[ROAR_NET2HOST16(info[3])] = ROAR_NET2HOST16(info[4]);
786 } else {
787  return -1;
788 }
789
790 if ( streams_set_mixer(stream) == -1 )
791  return -1;
792
793 mes->cmd     = ROAR_CMD_OK;
794 mes->datalen = 0;
795
796 return 0;
797}
798
799int req_on_get_vol (int client, struct roar_message * mes, char * data) {
800 uint16_t * info = (uint16_t *) mes->data;
801 int stream;
802 struct roar_stream_server * s;
803 int i;
804 int chans;
805
806 ROAR_DBG("req_on_get_vol(*) = ?");
807 ROAR_DBG("req_on_get_vol(*): mes->datalen=%i", mes->datalen);
808
809 if ( mes->datalen < (2*2) )
810  return -1;
811
812 if ( info[0] != 0 ) // version
813  return -1;
814
815 stream = ROAR_NET2HOST16(info[1]);
816 ROAR_DBG("req_on_get_vol(*): stream=%i", stream);
817
818 // TODO: change this code.
819 //       we should not directly change the stream object but use some stream_*()-func
820 //       for that job.
821
822 if ( stream < 0 || stream >= ROAR_STREAMS_MAX )
823  return -1;
824
825 s = g_streams[stream];
826
827 if ( s == NULL )
828  return -1;
829
830 ROAR_DBG("req_on_get_vol(*): s=%p", s);
831
832 // ok, we have everything
833
834 info[0] = 0;
835 info[1] = ROAR_HOST2NET16(chans = ROAR_STREAM(s)->info.channels);
836
837 for (i = 0; i < chans; i++)
838  info[2+i] = ROAR_HOST2NET16(s->mixer.mixer[i]);
839
840 mes->datalen = (2 + chans)*2;
841 mes->cmd = ROAR_CMD_OK;
842
843 return 0;
844}
845
846int req_on_add_data (int client, struct roar_message * mes, char * data) {
847 struct roar_buffer * b;
848 char               * buf;
849
850 if ( roar_buffer_new(&b, mes->datalen) == -1 ) {
851  ROAR_ERR("req_on_add_data(*): Can not alloc buffer space!");
852  ROAR_DBG("req_on_add_data(*) = -1");
853  return -1;
854 }
855
856 roar_buffer_get_data(b, (void **)&buf);
857
858 if ( data == NULL ) {
859  memcpy(buf, mes->data, mes->datalen);
860 } else {
861  memcpy(buf, data, mes->datalen);
862 }
863
864 if ( stream_add_buffer(mes->stream, b) == -1 ) {
865  roar_buffer_free(b);
866  return -1;
867 }
868
869 mes->cmd     = ROAR_CMD_OK_STOP;
870 mes->datalen = 0;
871
872 return 0;
873}
874
875//ll
Note: See TracBrowser for help on using the repository browser.