source: roaraudio/libroar/stream.c @ 3136:e9b53172083c

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

added support for config option force-{rate,bits,codec,channels}

File size: 17.1 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
395 info->block_size     = data[2];
396 info->pre_underruns  = data[3];
397 info->post_underruns = data[4];
398 info->codec          = data[5];
399 info->flags          = data[6];
400 info->delay          = data[7]*1000;
401
402 if ( m.datalen < 9*2 ) {
403  info->state         = ROAR_STREAMSTATE_UNKNOWN;
404  return 0;
405 } else {
406  info->state         = data[8];
407 }
408
409 if ( m.datalen < 10*2 ) {
410  return 0;
411 } else {
412  info->flags        |= ((uint32_t)data[9]) << 16;
413 }
414
415 return 0;
416}
417
418int roar_stream_get_name (struct roar_connection * con, struct roar_stream * s, char * name, size_t len) {
419 struct roar_message m;
420 uint16_t * data = (uint16_t *) m.data;
421
422 if ( con == NULL || s == NULL || name == NULL || len == 0 )
423  return -1;
424
425 name[0] = 0; // just in case...
426
427 m.cmd     = ROAR_CMD_GET_STREAM_PARA;
428 m.stream  = s->id;
429 m.datalen = 4;
430 m.pos     = 0;
431
432 data[0] = 0; // Version and reserved
433 data[1] = ROAR_STREAM_PARA_NAME; // stream
434
435 data[0] = ROAR_HOST2NET16(data[0]);
436 data[1] = ROAR_HOST2NET16(data[1]);
437
438 ROAR_DBG("roar_stream_get_name(*) = ?");
439
440 if ( roar_req(con, &m, NULL) == -1 )
441  return -1;
442
443 ROAR_DBG("roar_stream_get_name(*) = ?");
444
445 if ( m.cmd != ROAR_CMD_OK )
446  return -1;
447
448 ROAR_DBG("roar_stream_get_name(*) = ?");
449
450 if ( m.datalen < 4 )
451  return -1;
452
453 data[0] = ROAR_NET2HOST16(data[0]);
454 data[1] = ROAR_NET2HOST16(data[1]);
455
456 ROAR_DBG("roar_stream_get_name(*) = ?");
457
458 if ( data[0] != 0 || data[1] != ROAR_STREAM_PARA_NAME )
459  return -1;
460
461 m.datalen -= 4;
462
463 len--;
464
465 if ( len > m.datalen )
466  len = m.datalen;
467
468 strncpy(name, ((char*)m.data)+4, len);
469 name[len] = 0;
470
471 ROAR_DBG("roar_stream_get_name(*) = 0");
472
473 return 0;
474}
475
476int roar_stream_set_flags (struct roar_connection * con, struct roar_stream * s, int flags, int reset) {
477 struct roar_message m;
478 uint16_t * data = (uint16_t *) m.data;
479 int i;
480
481 m.cmd     = ROAR_CMD_SET_STREAM_PARA;
482 m.stream  = s->id;
483 m.datalen = 8;
484 m.pos     = 0;
485
486 data[0] = 0; // Version and reserved
487 data[1] = 2; // flags
488 data[2] = reset == ROAR_RESET_FLAG ? ROAR_RESET_FLAG : ROAR_SET_FLAG;
489 data[3] = flags;
490
491 for (i = 0; i < m.datalen/2; i++) {
492  data[i] = ROAR_HOST2NET16(data[i]);
493 }
494
495 if ( roar_req(con, &m, NULL) == -1 )
496  return -1;
497
498 if ( m.cmd != ROAR_CMD_OK )
499  return -1;
500
501 return 0;
502}
503
504#define _ROAR_STREAM_MESSAGE_LEN ((5+1)*4)
505
506int roar_stream_s2m     (struct roar_stream * s, struct roar_message * m) {
507 uint32_t * data;
508 int i;
509
510 if ( !(s && m) )
511  return -1;
512
513 m->datalen = _ROAR_STREAM_MESSAGE_LEN;
514 data = (uint32_t*) m->data;
515
516 data[0] = s->dir;
517 data[1] = s->pos_rel_id;
518 data[2] = s->info.rate;
519 data[3] = s->info.bits;
520 data[4] = s->info.channels;
521 data[5] = s->info.codec;
522
523 for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++)
524  data[i] = ROAR_HOST2NET32(data[i]);
525
526 ROAR_DBG("roar_stream_s2m(*): s->info:");
527 roar_debug_audio_info_print(&s->info);
528
529 m->pos = s->pos;
530
531 return 0;
532}
533int roar_stream_m2s     (struct roar_stream * s, struct roar_message * m) {
534 uint32_t * data;
535 int i;
536
537 if ( !(s && m) )
538  return -1;
539
540 if ( m->datalen != _ROAR_STREAM_MESSAGE_LEN )
541  return -1;
542
543 s->pos = m->pos;
544
545 data = (uint32_t*) m->data;
546
547 for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++)
548  data[i] = ROAR_NET2HOST32(data[i]);
549
550 s->id            = m->stream;
551 s->dir           = data[0];
552 s->pos_rel_id    = data[1];
553 s->info.rate     = data[2];
554 s->info.bits     = data[3];
555 s->info.channels = data[4];
556 s->info.codec    = data[5];
557
558 ROAR_DBG("roar_stream_m2s(*): s->info:");
559 roar_debug_audio_info_print(&s->info);
560
561 return 0;
562}
563
564// stream direction funcs:
565/*
566#define roar_dir2str(x)   ((x) == ROAR_DIR_PLAY   ? "play"   : (x) == ROAR_DIR_MONITOR ? "monitor" : \
567                           (x) == ROAR_DIR_FILTER ? "filter" : (x) == ROAR_DIR_RECORD  ? "record"  : \
568                           (x) == ROAR_DIR_OUTPUT ? "output" : (x) == ROAR_DIR_BIDIR   ? "bidir"   : \
569                           (x) == ROAR_DIR_MIXING ? "mixing" : \
570                           "unknown")
571*/
572
573struct {
574 int    dir;
575 char * name;
576} _libroar_dir[] = {
577 {ROAR_DIR_PLAY,        "play"       },
578 {ROAR_DIR_RECORD,      "record"     },
579 {ROAR_DIR_MONITOR,     "monitor"    },
580 {ROAR_DIR_FILTER,      "filter"     },
581 {ROAR_DIR_OUTPUT,      "output"     },
582 {ROAR_DIR_MIXING,      "mixing"     },
583 {ROAR_DIR_META,        "meta"       },
584 {ROAR_DIR_BIDIR,       "bidir"      },
585 {ROAR_DIR_THRU,        "thru"       },
586 {ROAR_DIR_BRIDGE,      "bridge"     },
587 {ROAR_DIR_MIDI_IN,     "midi_in"    },
588 {ROAR_DIR_MIDI_OUT,    "midi_out"   },
589 {ROAR_DIR_LIGHT_IN,    "light_in"   },
590 {ROAR_DIR_LIGHT_OUT,   "light_out"  },
591 {ROAR_DIR_RAW_IN,      "raw_in"     },
592 {ROAR_DIR_RAW_OUT,     "raw_out"    },
593 {ROAR_DIR_COMPLEX_IN,  "complex_in" },
594 {ROAR_DIR_COMPLEX_OUT, "complex_out"},
595 {ROAR_DIR_RDTCS_IN,    "rdtcs_in"   },
596 {ROAR_DIR_RDTCS_OUT,   "rdtcs_out"  },
597 {-1,                   "unknown"    }
598};
599
600char * roar_dir2str (int dir) {
601 int i;
602
603 for (i = 0; _libroar_dir[i].dir != -1; i++)
604  if ( _libroar_dir[i].dir == dir )
605   return _libroar_dir[i].name;
606
607 return _libroar_dir[i].name;
608}
609
610int roar_str2dir (char * name) {
611 int i;
612
613 for (i = 0; _libroar_dir[i].dir != -1; i++)
614  if ( !strcmp(_libroar_dir[i].name, name) )
615   return _libroar_dir[i].dir;
616
617 return _libroar_dir[i].dir;
618}
619
620// codec funcs:
621
622/*
623#define roar_codec2str(x) ((x) == ROAR_CODEC_PCM_S_LE  ? "pcm_s_le"  : (x) == ROAR_CODEC_PCM_S_BE  ? "pcm_s_be"  : \
624                           (x) == ROAR_CODEC_PCM_S_PDP ? "pcm_s_pdp" : (x) == ROAR_CODEC_MIDI_FILE ? "midi_file" : \
625                           "unknown" )
626*/
627
628struct {
629 int    codec;
630 char * name;
631} _libroar_codec[] = {
632 // PCM:
633 {ROAR_CODEC_PCM_S_LE,    "pcm_s_le"   },
634 {ROAR_CODEC_PCM_S_BE,    "pcm_s_be"   },
635 {ROAR_CODEC_PCM_S_PDP,   "pcm_s_pdp"  },
636 {ROAR_CODEC_PCM_U_LE,    "pcm_u_le"   },
637 {ROAR_CODEC_PCM_U_BE,    "pcm_u_be"   },
638 {ROAR_CODEC_PCM_U_PDP,   "pcm_u_pdp"  },
639 {ROAR_CODEC_DEFAULT,     "default"    }, // alias
640 {ROAR_CODEC_DEFAULT,     "pcm"        }, // alias
641 {ROAR_CODEC_DEFAULT,     "raw"        }, // alias
642
643 // MIDI:
644 {ROAR_CODEC_MIDI_FILE,   "midi_file"  },
645 {ROAR_CODEC_MIDI,        "midi"       },
646
647 // XIPH:
648 {ROAR_CODEC_OGG_VORBIS,  "ogg_vorbis" },
649 {ROAR_CODEC_OGG_VORBIS,  "vorbis"     }, // alias
650 {ROAR_CODEC_FLAC,        "flac"       },
651 {ROAR_CODEC_OGG_SPEEX,   "ogg_speex"  },
652 {ROAR_CODEC_OGG_SPEEX,   "speex"      }, // alias
653 {ROAR_CODEC_OGG_FLAC,    "ogg_flac"   },
654 {ROAR_CODEC_OGG_GENERAL, "ogg_general"},
655 {ROAR_CODEC_OGG_CELT,    "ogg_celt"   },
656 {ROAR_CODEC_OGG,         "ogg"        },
657 {ROAR_CODEC_ROAR_CELT,   "roar_celt"  },
658 {ROAR_CODEC_ROAR_SPEEX,  "roar_speex" },
659
660 // RAUM:
661 {ROAR_CODEC_RAUM,        "raum"       },
662 {ROAR_CODEC_RAUM_VORBIS, "raum_vorbis"},
663 {ROAR_CODEC_RAUM_FLAC,   "raum_flac"  },
664
665 // RIFF/WAVE like:
666 {ROAR_CODEC_RIFF_WAVE,   "riff_wave"  },
667 {ROAR_CODEC_RIFF_WAVE,   "wave"       }, // alias
668 {ROAR_CODEC_RIFF_WAVE,   "wav"        }, // alias
669
670 //Log codecs:
671 {ROAR_CODEC_ALAW,        "alaw"       },
672 {ROAR_CODEC_MULAW,       "mulaw"      },
673 {ROAR_CODEC_MULAW,       "ulaw"       }, // alias
674
675 // Meta Codecs:
676 {ROAR_CODEC_META_VCLT,     "meta_vclt"    },
677 {ROAR_CODEC_META_RALT,     "meta_ralt"    },
678 {ROAR_CODEC_META_RALB,     "meta_ralb"    },
679 {ROAR_CODEC_META_RALB_LE,  "meta_ralb_le" },
680 {ROAR_CODEC_META_RALB_BE,  "meta_ralb_be" },
681 {ROAR_CODEC_META_RALB_PDP, "meta_ralb_pdp"},
682
683 // light control:
684 {ROAR_CODEC_DMX512,      "dmx512"     },
685 {ROAR_CODEC_ROARDMX,     "roardmx"    },
686
687 // Radio Data and Transmitter Control System:
688 {ROAR_CODEC_RDS,         "rds"        },
689
690 // User specific:
691 {ROAR_CODEC_USER0,       "user0"      },
692 {ROAR_CODEC_USER1,       "user1"      },
693 {ROAR_CODEC_USER2,       "user2"      },
694 {ROAR_CODEC_USER3,       "user3"      },
695 {ROAR_CODEC_USER4,       "user4"      },
696 {ROAR_CODEC_USER5,       "user5"      },
697 {ROAR_CODEC_USER6,       "user6"      },
698 {ROAR_CODEC_USER7,       "user7"      },
699 {ROAR_CODEC_USER8,       "user8"      },
700 {ROAR_CODEC_USER9,       "user9"      },
701 {ROAR_CODEC_USER10,      "user10"     },
702 {ROAR_CODEC_USER11,      "user11"     },
703 {ROAR_CODEC_USER12,      "user12"     },
704 {ROAR_CODEC_USER13,      "user13"     },
705 {ROAR_CODEC_USER14,      "user14"     },
706 {ROAR_CODEC_USER15,      "user15"     },
707 {-1, NULL}
708};
709
710int roar_str2codec(char * codec) {
711 int i;
712 int guess;
713
714 if ( codec == NULL || *codec == 0 )
715  return ROAR_CODEC_DEFAULT;
716
717 if ( (guess = atoi(codec)) > 0 )
718  return guess;
719
720 if ( codec == NULL || *codec == 0 )
721  return ROAR_CODEC_DEFAULT;
722
723 for (i = 0; _libroar_codec[i].codec != -1; i++)
724  if ( strcasecmp(_libroar_codec[i].name, codec) == 0 )
725   return _libroar_codec[i].codec;
726
727 return -1;
728}
729
730
731char * roar_codec2str (int codec) {
732 int i;
733
734 for (i = 0; _libroar_codec[i].codec != -1; i++)
735  if ( _libroar_codec[i].codec == codec )
736   return _libroar_codec[i].name;
737
738 return "unknown";
739}
740
741char * roar_streamstate2str(int streamstate) {
742 switch (streamstate) {
743  case ROAR_STREAMSTATE_UNUSED:  return "unused";  break;
744  case ROAR_STREAMSTATE_INITING: return "initing"; break;
745  case ROAR_STREAMSTATE_NEW:     return "new";     break;
746  case ROAR_STREAMSTATE_OLD:     return "old";     break;
747  case ROAR_STREAMSTATE_CLOSING: return "closing"; break;
748 }
749
750 return "unknown";
751}
752
753//ll
Note: See TracBrowser for help on using the repository browser.