source: roaraudio/libroar/stream.c @ 3213:da8251c98c0a

Last change on this file since 3213:da8251c98c0a was 3213:da8251c98c0a, checked in by phi, 14 years ago

support to transpher mixer stream id

File size: 17.2 KB
Line 
1//stream.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of libroar 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 *  libroar 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 *  NOTE for everyone want's to change something and send patches:
24 *  read README and HACKING! There a addition information on
25 *  the license of this document you need to read before you send
26 *  any patches.
27 *
28 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
29 *  or libpulse*:
30 *  The libs libroaresd, libroararts and libroarpulse link this lib
31 *  and are therefore GPL. Because of this it may be illigal to use
32 *  them with any software that uses libesd, libartsc or libpulse*.
33 */
34
35#include "libroar.h"
36
37int roar_stream_connect (struct roar_connection * con, struct roar_stream * s, int dir) {
38 struct roar_libroar_config * config = roar_libroar_get_config();
39 struct roar_stream  ms;
40 struct roar_message m;
41
42 s->dir = dir;
43
44 memcpy(&ms, s, sizeof(ms));
45
46 m.cmd     = ROAR_CMD_NEW_STREAM;
47 m.stream  = -1;
48 m.pos     = 0;
49
50 if ( config != NULL ) {
51  if ( config->info.rate )
52   ms.info.rate = config->info.rate;
53  if ( config->info.bits )
54   ms.info.bits = config->info.bits;
55  if ( config->info.channels )
56   ms.info.channels = config->info.channels;
57  if ( config->info.codec )
58   ms.info.codec = config->info.codec;
59 }
60
61 roar_stream_s2m(&ms, &m);
62
63 if ( roar_req(con, &m, NULL) != 0 )
64  return -1;
65
66 if ( m.cmd == ROAR_CMD_OK ) {
67  s->id = m.stream;
68
69  ROAR_DBG("roar_stream_connect(*) = 0");
70  return 0;
71 }
72
73 ROAR_ERR("roar_stream_connect(*): Connecting new stream faild!");
74 ROAR_DBG("roar_stream_connect(*) = -1");
75 return -1;
76}
77
78int roar_stream_new (struct roar_stream * s, unsigned int rate,
79                     unsigned int channels, unsigned int bits, unsigned int codec) {
80
81 if ( s == NULL )
82  return -1;
83
84 s->fh         = -1;
85 s->id         = -1;
86 s->pos        =  0;
87 s->pos_rel_id = -1;
88
89 s->dir        = ROAR_DIR_DEFAULT;
90
91/*
92 s->datalen    = 0;
93 s->offset     = 0;
94
95 s->database   = NULL;
96 s->dataoff    = NULL;
97*/
98
99 s->info.rate     = rate;
100 s->info.channels = channels;
101 s->info.bits     = bits;
102 s->info.codec    = codec;
103
104 if ( bits > ROAR_BITS_MAX )
105  return -1;
106
107 return 0;
108}
109
110int roar_stream_set_rel_id(struct roar_stream * s, int id) {
111 if ( s == NULL )
112  return -1;
113
114 s->pos_rel_id = id;
115
116 return 0;
117}
118
119int roar_stream_get_rel_id(struct roar_stream * s) {
120 if ( s == NULL )
121  return -1;
122
123 return s->pos_rel_id;
124}
125
126int roar_stream_new_by_id(struct roar_stream * s, int id) {
127 if ( s == NULL )
128  return -1;
129
130 if ( roar_stream_new_empty(s) == -1 )
131  return -1;
132
133 return roar_stream_set_id(s, id);
134}
135
136int roar_stream_new_empty(struct roar_stream * s) {
137 if ( s == NULL )
138  return -1;
139
140 return roar_stream_new(s, 0, 0, 0, 0);
141}
142
143int roar_stream_set_id (struct roar_stream * s, int id) {
144 if ( s == NULL )
145  return -1;
146
147 s->id = id;
148
149 return 0;
150}
151
152int roar_stream_get_id (struct roar_stream * s) {
153 if ( s == NULL )
154  return -1;
155
156 return s->id;
157}
158
159int roar_stream_set_fh (struct roar_stream * s, int fh) {
160 if ( s == NULL )
161  return -1;
162
163 s->fh = fh;
164
165 return 0;
166}
167
168int roar_stream_get_fh (struct roar_stream * s) {
169 if ( s == NULL )
170  return -1;
171
172 return s->fh;
173}
174
175int roar_stream_set_dir (struct roar_stream * s, int dir) {
176 if ( s == NULL )
177  return -1;
178
179 s->dir = dir;
180
181 return 0;
182}
183
184int roar_stream_get_dir (struct roar_stream * s) {
185 if ( s == NULL )
186  return -1;
187
188 return s->dir;
189}
190
191
192int roar_stream_exec    (struct roar_connection * con, struct roar_stream * s) {
193 struct roar_message m;
194
195 m.cmd     = ROAR_CMD_EXEC_STREAM;
196 m.stream  = s->id;
197 m.datalen = 0;
198 m.pos     = 0;
199
200 if ( roar_req(con, &m, NULL) == -1 )
201  return -1;
202
203 if ( m.cmd == ROAR_CMD_OK )
204  return 0;
205 return -1;
206}
207
208int roar_stream_connect_to (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port) {
209 struct roar_message m;
210
211 if ( roar_stream_connect_to_ask(con, s, type, host, port) == -1 )
212  return -1;
213
214 if ( roar_recv_message(con, &m, NULL) == -1 )
215  return -1;
216
217 if ( m.cmd == ROAR_CMD_OK )
218  return 0;
219 return -1;
220}
221
222int roar_stream_connect_to_ask (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port) {
223 struct roar_message m;
224 int len = 0;
225
226 if ( host == NULL )
227  return -1;
228
229 ROAR_DBG("roar_stream_connect_to_ask(*): Ask the server to connect to: %s:%i", host, port);
230
231 m.cmd     = ROAR_CMD_CON_STREAM;
232 m.stream  = s->id;
233 m.pos     = 0;
234
235 m.data[0] = 0;
236 m.data[1] = type;
237 ((uint16_t*)&(m.data))[1] = ROAR_HOST2NET16(port);
238
239 len = strlen(host);
240
241 if ( len > 76 )
242  return -1;
243
244 strncpy(&(m.data[4]), host, len);
245
246 m.datalen = len + 4;
247
248 if ( roar_send_message(con, &m, NULL) == -1 )
249  return -1;
250
251 return 0;
252}
253
254int roar_stream_passfh  (struct roar_connection * con, struct roar_stream * s, int fh) {
255 struct roar_message m;
256 int confh;
257
258 m.cmd     = ROAR_CMD_PASSFH;
259 m.stream  = s->id;
260 m.pos     = 0;
261 m.datalen = 0;
262
263 ROAR_DBG("roar_stream_passfh(con=%p{...}, s={.id=%i,...}, fh=%i) = ?", con, s->id, fh);
264
265 if ( (confh = roar_get_connection_fh(con)) == -1 )
266  return -1;
267
268 if ( roar_send_message(con, &m, NULL) == -1 ) {
269  ROAR_DBG("roar_stream_passfh(con=%p{...}, s={.id=%i,...}, fh=%i) = -1 // can not send message", con, s->id, fh);
270  return -1;
271 }
272
273 ROAR_DBG("roar_stream_passfh(*): msg send");
274
275 if ( roar_socket_send_fh(confh, fh, NULL, 0) == -1 )
276  return -1;
277
278 ROAR_DBG("roar_stream_passfh(*): fh send");
279
280 if ( roar_recv_message(con, &m, NULL) == -1 )
281  return -1;
282
283 ROAR_DBG("roar_stream_passfh(*): mes recved");
284
285 if ( m.cmd == ROAR_CMD_OK )
286  return 0;
287
288 return -1;
289}
290
291int roar_stream_attach_simple (struct roar_connection * con, struct roar_stream * s, int client) {
292 struct roar_message m;
293 uint16_t * info = (uint16_t *) m.data;
294 int i;
295
296 m.cmd     = ROAR_CMD_ATTACH;
297 m.stream  = s->id;
298 m.pos     = 0;
299 m.datalen = 6;
300
301 info[0] = 0;
302 info[1] = ROAR_ATTACH_SIMPLE;
303 info[2] = client;
304
305 for (i = 0; i < m.datalen/2; i++) {
306  info[i] = ROAR_HOST2NET16(info[i]);
307 }
308
309 if ( roar_req(con, &m, NULL) == -1 )
310  return -1;
311
312 if ( m.cmd != ROAR_CMD_OK )
313  return -1;
314
315 return 0;
316}
317
318int roar_stream_add_data (struct roar_connection * con, struct roar_stream * s, char * data, size_t len) {
319 struct roar_message m;
320
321 m.cmd     = ROAR_CMD_ADD_DATA;
322 m.stream  = s->id;
323 m.pos     = 0;
324 m.datalen = len;
325
326// if ( roar_req(con, &m, (void**)&data) == -1 )
327//  return -1;
328 if ( roar_send_message(con, &m, data) != 0 )
329  return -1;
330
331 if ( roar_recv_message(con, &m, NULL) == -1 )
332  return -1;
333
334 if ( m.cmd == ROAR_CMD_OK )
335  return 0;
336 return -1;
337}
338
339int roar_stream_send_data (struct roar_connection * con, struct roar_stream * s, char * data, size_t len) {
340 if ( ! s )
341  return -1;
342
343 if ( s->fh == -1 ) {
344  if ( !con )
345   return -1;
346
347  if ( roar_stream_add_data(con, s, data, len) == -1 )
348   return -1;
349
350  return len;
351 }
352
353#ifdef ROAR_HAVE_IO_POSIX
354 return write(s->fh, data, len);
355#endif
356
357 return -1;
358}
359
360int roar_stream_get_info (struct roar_connection * con, struct roar_stream * s, struct roar_stream_info * info) {
361 struct roar_message m;
362 uint16_t * data = (uint16_t *) m.data;
363 int i;
364
365 m.cmd     = ROAR_CMD_GET_STREAM_PARA;
366 m.stream  = s->id;
367 m.datalen = 4;
368 m.pos     = 0;
369
370 data[0] = 0; // Version and reserved
371 data[1] = ROAR_STREAM_PARA_INFO; // stream
372
373 for (i = 0; i < m.datalen/2; i++) {
374  data[i] = ROAR_HOST2NET16(data[i]);
375 }
376
377 if ( roar_req(con, &m, NULL) == -1 )
378  return -1;
379
380 if ( m.cmd != ROAR_CMD_OK )
381  return -1;
382
383 for (i = 0; i < m.datalen/2; i++) {
384  data[i] = ROAR_NET2HOST16(data[i]);
385 }
386
387 if ( m.datalen < 7*2 )
388  return -1;
389
390 if ( data[0] != 0 || data[1] != 1 )
391  return -1;
392
393 memset(info, 0, sizeof(struct roar_stream_info));
394 info->mixer = -1;
395
396 info->block_size     = data[2];
397 info->pre_underruns  = data[3];
398 info->post_underruns = data[4];
399 info->codec          = data[5];
400 info->flags          = data[6];
401 info->delay          = data[7]*1000;
402
403 if ( m.datalen < 9*2 ) {
404  info->state         = ROAR_STREAMSTATE_UNKNOWN;
405  return 0;
406 } else {
407  info->state         = data[8];
408 }
409
410 if ( m.datalen < 10*2 ) {
411  return 0;
412 } else {
413  info->flags        |= ((uint32_t)data[9]) << 16;
414 }
415
416 if ( m.datalen < 11*2 ) {
417  return 0;
418 } else {
419  info->mixer         = data[10];
420 }
421
422 return 0;
423}
424
425int roar_stream_get_name (struct roar_connection * con, struct roar_stream * s, char * name, size_t len) {
426 struct roar_message m;
427 uint16_t * data = (uint16_t *) m.data;
428
429 if ( con == NULL || s == NULL || name == NULL || len == 0 )
430  return -1;
431
432 name[0] = 0; // just in case...
433
434 m.cmd     = ROAR_CMD_GET_STREAM_PARA;
435 m.stream  = s->id;
436 m.datalen = 4;
437 m.pos     = 0;
438
439 data[0] = 0; // Version and reserved
440 data[1] = ROAR_STREAM_PARA_NAME; // stream
441
442 data[0] = ROAR_HOST2NET16(data[0]);
443 data[1] = ROAR_HOST2NET16(data[1]);
444
445 ROAR_DBG("roar_stream_get_name(*) = ?");
446
447 if ( roar_req(con, &m, NULL) == -1 )
448  return -1;
449
450 ROAR_DBG("roar_stream_get_name(*) = ?");
451
452 if ( m.cmd != ROAR_CMD_OK )
453  return -1;
454
455 ROAR_DBG("roar_stream_get_name(*) = ?");
456
457 if ( m.datalen < 4 )
458  return -1;
459
460 data[0] = ROAR_NET2HOST16(data[0]);
461 data[1] = ROAR_NET2HOST16(data[1]);
462
463 ROAR_DBG("roar_stream_get_name(*) = ?");
464
465 if ( data[0] != 0 || data[1] != ROAR_STREAM_PARA_NAME )
466  return -1;
467
468 m.datalen -= 4;
469
470 len--;
471
472 if ( len > m.datalen )
473  len = m.datalen;
474
475 strncpy(name, ((char*)m.data)+4, len);
476 name[len] = 0;
477
478 ROAR_DBG("roar_stream_get_name(*) = 0");
479
480 return 0;
481}
482
483int roar_stream_set_flags (struct roar_connection * con, struct roar_stream * s, int flags, int reset) {
484 struct roar_message m;
485 uint16_t * data = (uint16_t *) m.data;
486 int i;
487
488 m.cmd     = ROAR_CMD_SET_STREAM_PARA;
489 m.stream  = s->id;
490 m.datalen = 8;
491 m.pos     = 0;
492
493 data[0] = 0; // Version and reserved
494 data[1] = 2; // flags
495 data[2] = reset == ROAR_RESET_FLAG ? ROAR_RESET_FLAG : ROAR_SET_FLAG;
496 data[3] = flags;
497
498 for (i = 0; i < m.datalen/2; i++) {
499  data[i] = ROAR_HOST2NET16(data[i]);
500 }
501
502 if ( roar_req(con, &m, NULL) == -1 )
503  return -1;
504
505 if ( m.cmd != ROAR_CMD_OK )
506  return -1;
507
508 return 0;
509}
510
511#define _ROAR_STREAM_MESSAGE_LEN ((5+1)*4)
512
513int roar_stream_s2m     (struct roar_stream * s, struct roar_message * m) {
514 uint32_t * data;
515 int i;
516
517 if ( !(s && m) )
518  return -1;
519
520 m->datalen = _ROAR_STREAM_MESSAGE_LEN;
521 data = (uint32_t*) m->data;
522
523 data[0] = s->dir;
524 data[1] = s->pos_rel_id;
525 data[2] = s->info.rate;
526 data[3] = s->info.bits;
527 data[4] = s->info.channels;
528 data[5] = s->info.codec;
529
530 for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++)
531  data[i] = ROAR_HOST2NET32(data[i]);
532
533 ROAR_DBG("roar_stream_s2m(*): s->info:");
534 roar_debug_audio_info_print(&s->info);
535
536 m->pos = s->pos;
537
538 return 0;
539}
540int roar_stream_m2s     (struct roar_stream * s, struct roar_message * m) {
541 uint32_t * data;
542 int i;
543
544 if ( !(s && m) )
545  return -1;
546
547 if ( m->datalen != _ROAR_STREAM_MESSAGE_LEN )
548  return -1;
549
550 s->pos = m->pos;
551
552 data = (uint32_t*) m->data;
553
554 for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++)
555  data[i] = ROAR_NET2HOST32(data[i]);
556
557 s->id            = m->stream;
558 s->dir           = data[0];
559 s->pos_rel_id    = data[1];
560 s->info.rate     = data[2];
561 s->info.bits     = data[3];
562 s->info.channels = data[4];
563 s->info.codec    = data[5];
564
565 ROAR_DBG("roar_stream_m2s(*): s->info:");
566 roar_debug_audio_info_print(&s->info);
567
568 return 0;
569}
570
571// stream direction funcs:
572/*
573#define roar_dir2str(x)   ((x) == ROAR_DIR_PLAY   ? "play"   : (x) == ROAR_DIR_MONITOR ? "monitor" : \
574                           (x) == ROAR_DIR_FILTER ? "filter" : (x) == ROAR_DIR_RECORD  ? "record"  : \
575                           (x) == ROAR_DIR_OUTPUT ? "output" : (x) == ROAR_DIR_BIDIR   ? "bidir"   : \
576                           (x) == ROAR_DIR_MIXING ? "mixing" : \
577                           "unknown")
578*/
579
580struct {
581 int    dir;
582 char * name;
583} _libroar_dir[] = {
584 {ROAR_DIR_PLAY,        "play"       },
585 {ROAR_DIR_RECORD,      "record"     },
586 {ROAR_DIR_MONITOR,     "monitor"    },
587 {ROAR_DIR_FILTER,      "filter"     },
588 {ROAR_DIR_OUTPUT,      "output"     },
589 {ROAR_DIR_MIXING,      "mixing"     },
590 {ROAR_DIR_META,        "meta"       },
591 {ROAR_DIR_BIDIR,       "bidir"      },
592 {ROAR_DIR_THRU,        "thru"       },
593 {ROAR_DIR_BRIDGE,      "bridge"     },
594 {ROAR_DIR_MIDI_IN,     "midi_in"    },
595 {ROAR_DIR_MIDI_OUT,    "midi_out"   },
596 {ROAR_DIR_LIGHT_IN,    "light_in"   },
597 {ROAR_DIR_LIGHT_OUT,   "light_out"  },
598 {ROAR_DIR_RAW_IN,      "raw_in"     },
599 {ROAR_DIR_RAW_OUT,     "raw_out"    },
600 {ROAR_DIR_COMPLEX_IN,  "complex_in" },
601 {ROAR_DIR_COMPLEX_OUT, "complex_out"},
602 {ROAR_DIR_RDTCS_IN,    "rdtcs_in"   },
603 {ROAR_DIR_RDTCS_OUT,   "rdtcs_out"  },
604 {-1,                   "unknown"    }
605};
606
607char * roar_dir2str (int dir) {
608 int i;
609
610 for (i = 0; _libroar_dir[i].dir != -1; i++)
611  if ( _libroar_dir[i].dir == dir )
612   return _libroar_dir[i].name;
613
614 return _libroar_dir[i].name;
615}
616
617int roar_str2dir (char * name) {
618 int i;
619
620 for (i = 0; _libroar_dir[i].dir != -1; i++)
621  if ( !strcmp(_libroar_dir[i].name, name) )
622   return _libroar_dir[i].dir;
623
624 return _libroar_dir[i].dir;
625}
626
627// codec funcs:
628
629/*
630#define roar_codec2str(x) ((x) == ROAR_CODEC_PCM_S_LE  ? "pcm_s_le"  : (x) == ROAR_CODEC_PCM_S_BE  ? "pcm_s_be"  : \
631                           (x) == ROAR_CODEC_PCM_S_PDP ? "pcm_s_pdp" : (x) == ROAR_CODEC_MIDI_FILE ? "midi_file" : \
632                           "unknown" )
633*/
634
635struct {
636 int    codec;
637 char * name;
638} _libroar_codec[] = {
639 // PCM:
640 {ROAR_CODEC_PCM_S_LE,    "pcm_s_le"   },
641 {ROAR_CODEC_PCM_S_BE,    "pcm_s_be"   },
642 {ROAR_CODEC_PCM_S_PDP,   "pcm_s_pdp"  },
643 {ROAR_CODEC_PCM_U_LE,    "pcm_u_le"   },
644 {ROAR_CODEC_PCM_U_BE,    "pcm_u_be"   },
645 {ROAR_CODEC_PCM_U_PDP,   "pcm_u_pdp"  },
646 {ROAR_CODEC_DEFAULT,     "default"    }, // alias
647 {ROAR_CODEC_DEFAULT,     "pcm"        }, // alias
648 {ROAR_CODEC_DEFAULT,     "raw"        }, // alias
649
650 // MIDI:
651 {ROAR_CODEC_MIDI_FILE,   "midi_file"  },
652 {ROAR_CODEC_MIDI,        "midi"       },
653
654 // XIPH:
655 {ROAR_CODEC_OGG_VORBIS,  "ogg_vorbis" },
656 {ROAR_CODEC_OGG_VORBIS,  "vorbis"     }, // alias
657 {ROAR_CODEC_FLAC,        "flac"       },
658 {ROAR_CODEC_OGG_SPEEX,   "ogg_speex"  },
659 {ROAR_CODEC_OGG_SPEEX,   "speex"      }, // alias
660 {ROAR_CODEC_OGG_FLAC,    "ogg_flac"   },
661 {ROAR_CODEC_OGG_GENERAL, "ogg_general"},
662 {ROAR_CODEC_OGG_CELT,    "ogg_celt"   },
663 {ROAR_CODEC_OGG,         "ogg"        },
664 {ROAR_CODEC_ROAR_CELT,   "roar_celt"  },
665 {ROAR_CODEC_ROAR_SPEEX,  "roar_speex" },
666
667 // RAUM:
668 {ROAR_CODEC_RAUM,        "raum"       },
669 {ROAR_CODEC_RAUM_VORBIS, "raum_vorbis"},
670 {ROAR_CODEC_RAUM_FLAC,   "raum_flac"  },
671
672 // RIFF/WAVE like:
673 {ROAR_CODEC_RIFF_WAVE,   "riff_wave"  },
674 {ROAR_CODEC_RIFF_WAVE,   "wave"       }, // alias
675 {ROAR_CODEC_RIFF_WAVE,   "wav"        }, // alias
676
677 //Log codecs:
678 {ROAR_CODEC_ALAW,        "alaw"       },
679 {ROAR_CODEC_MULAW,       "mulaw"      },
680 {ROAR_CODEC_MULAW,       "ulaw"       }, // alias
681
682 // Meta Codecs:
683 {ROAR_CODEC_META_VCLT,     "meta_vclt"    },
684 {ROAR_CODEC_META_RALT,     "meta_ralt"    },
685 {ROAR_CODEC_META_RALB,     "meta_ralb"    },
686 {ROAR_CODEC_META_RALB_LE,  "meta_ralb_le" },
687 {ROAR_CODEC_META_RALB_BE,  "meta_ralb_be" },
688 {ROAR_CODEC_META_RALB_PDP, "meta_ralb_pdp"},
689
690 // light control:
691 {ROAR_CODEC_DMX512,      "dmx512"     },
692 {ROAR_CODEC_ROARDMX,     "roardmx"    },
693
694 // Radio Data and Transmitter Control System:
695 {ROAR_CODEC_RDS,         "rds"        },
696
697 // User specific:
698 {ROAR_CODEC_USER0,       "user0"      },
699 {ROAR_CODEC_USER1,       "user1"      },
700 {ROAR_CODEC_USER2,       "user2"      },
701 {ROAR_CODEC_USER3,       "user3"      },
702 {ROAR_CODEC_USER4,       "user4"      },
703 {ROAR_CODEC_USER5,       "user5"      },
704 {ROAR_CODEC_USER6,       "user6"      },
705 {ROAR_CODEC_USER7,       "user7"      },
706 {ROAR_CODEC_USER8,       "user8"      },
707 {ROAR_CODEC_USER9,       "user9"      },
708 {ROAR_CODEC_USER10,      "user10"     },
709 {ROAR_CODEC_USER11,      "user11"     },
710 {ROAR_CODEC_USER12,      "user12"     },
711 {ROAR_CODEC_USER13,      "user13"     },
712 {ROAR_CODEC_USER14,      "user14"     },
713 {ROAR_CODEC_USER15,      "user15"     },
714 {-1, NULL}
715};
716
717int roar_str2codec(char * codec) {
718 int i;
719 int guess;
720
721 if ( codec == NULL || *codec == 0 )
722  return ROAR_CODEC_DEFAULT;
723
724 if ( (guess = atoi(codec)) > 0 )
725  return guess;
726
727 if ( codec == NULL || *codec == 0 )
728  return ROAR_CODEC_DEFAULT;
729
730 for (i = 0; _libroar_codec[i].codec != -1; i++)
731  if ( strcasecmp(_libroar_codec[i].name, codec) == 0 )
732   return _libroar_codec[i].codec;
733
734 return -1;
735}
736
737
738char * roar_codec2str (int codec) {
739 int i;
740
741 for (i = 0; _libroar_codec[i].codec != -1; i++)
742  if ( _libroar_codec[i].codec == codec )
743   return _libroar_codec[i].name;
744
745 return "unknown";
746}
747
748char * roar_streamstate2str(int streamstate) {
749 switch (streamstate) {
750  case ROAR_STREAMSTATE_UNUSED:  return "unused";  break;
751  case ROAR_STREAMSTATE_INITING: return "initing"; break;
752  case ROAR_STREAMSTATE_NEW:     return "new";     break;
753  case ROAR_STREAMSTATE_OLD:     return "old";     break;
754  case ROAR_STREAMSTATE_CLOSING: return "closing"; break;
755 }
756
757 return "unknown";
758}
759
760//ll
Note: See TracBrowser for help on using the repository browser.