source: roaraudio/roard/sources.c @ 555:3e21244380f6

Last change on this file since 555:3e21244380f6 was 555:3e21244380f6, checked in by phi, 16 years ago

removed CELT_PREFIX and added INCPATH

File size: 2.9 KB
Line 
1//sources.c:
2
3#include "roard.h"
4
5int sources_init (void) {
6 g_source_client = -1;
7 return 0;
8}
9
10int sources_set_client (int client) {
11 if ( client >= 0 ) {
12  g_source_client = client;
13  return 0;
14 } else {
15  return -1;
16 }
17}
18
19int sources_free (void) {
20 return 0;
21}
22
23int sources_add (char * driver, char * device, char * container, char * options, int primary) {
24 if ( strcmp(driver, "raw") == 0 ) {
25  return sources_add_raw(driver, device, container, options, primary);
26 } else if ( strcmp(driver, "wav") == 0 ) {
27  return sources_add_wav(driver, device, container, options, primary);
28 } else if ( strcmp(driver, "cf") == 0 ) {
29  return sources_add_cf(driver, device, container, options, primary);
30 }
31
32 return -1;
33}
34
35int sources_add_raw (char * driver, char * device, char * container, char * options, int primary) {
36 int stream;
37 int fh;
38 struct roar_stream * s;
39
40 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
41  return -1;
42 }
43
44 if ( (stream = streams_new()) == -1 ) {
45  close(fh);
46  return -1;
47 }
48
49 streams_get(stream, (struct roar_stream_server **)&s);
50
51 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
52
53 s->dir        = ROAR_DIR_PLAY;
54 s->pos_rel_id = -1;
55
56 streams_set_fh(stream, fh);
57
58 client_stream_add(g_source_client, stream);
59
60 return 0;
61}
62
63int sources_add_wav (char * driver, char * device, char * container, char * options, int primary) {
64 int stream;
65 int fh;
66 char buf[44];
67 struct roar_stream * s;
68
69 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
70  return -1;
71 }
72
73 if (read(fh, buf, 44) != 44) {
74  close(fh);
75  return -1;
76 }
77
78 if ( (stream = streams_new()) == -1 ) {
79  close(fh);
80  return -1;
81 }
82
83 streams_get(stream, (struct roar_stream_server **)&s);
84
85 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
86
87  memcpy(&(s->info.rate    ), buf+24, 4);
88  memcpy(&(s->info.channels), buf+22, 2);
89  memcpy(&(s->info.bits    ), buf+34, 2);
90
91 s->dir        = ROAR_DIR_PLAY;
92 s->pos_rel_id = -1;
93
94 streams_set_fh(stream, fh);
95
96 client_stream_add(g_source_client, stream);
97
98 return 0;
99}
100
101int sources_add_cf (char * driver, char * device, char * container, char * options, int primary) {
102 int  stream;
103 int  fh;
104 int  codec;
105 int  len;
106 char buf[64];
107 struct roar_stream * s;
108
109 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
110  return -1;
111 }
112
113 if ( !options ) {
114  if ( (len = read(fh, buf, 64)) < 1 ) {
115   close(fh);
116   return -1;
117  }
118
119  if ( lseek(fh, -len, SEEK_CUR) == (off_t)-1 ) {
120   close(fh);
121   return -1;
122  }
123
124  if ( (codec = roar_file_codecdetect(buf, len)) == -1 ) {
125   close(fh);
126   return -1;
127  }
128 } else {
129  if ( (codec = roar_str2codec(options)) == -1 ) {
130   close(fh);
131   return -1;
132  }
133 }
134
135 if ( (stream = streams_new()) == -1 ) {
136  close(fh);
137  return -1;
138 }
139
140 streams_get(stream, (struct roar_stream_server **)&s);
141
142 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
143
144 s->dir        = ROAR_DIR_PLAY;
145 s->pos_rel_id = -1;
146 s->info.codec = codec;
147
148 streams_set_fh(stream, fh);
149
150 client_stream_add(g_source_client, stream);
151
152 return 0;
153}
154
155//ll
Note: See TracBrowser for help on using the repository browser.