source: roaraudio/libroar/stream.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

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