source: roaraudio/roard/sources.c @ 1022:fe708cd3a6a6

Last change on this file since 1022:fe708cd3a6a6 was 1022:fe708cd3a6a6, checked in by phi, 15 years ago

added roar source driver

File size: 5.2 KB
Line 
1//sources.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 sources_init (void) {
28 g_source_client = -1;
29 return 0;
30}
31
32int sources_set_client (int client) {
33 if ( client >= 0 ) {
34  g_source_client = client;
35  return 0;
36 } else {
37  return -1;
38 }
39}
40
41int sources_free (void) {
42 return 0;
43}
44
45int sources_add (char * driver, char * device, char * container, char * options, int primary) {
46 if ( strcmp(driver, "raw") == 0 ) {
47  return sources_add_raw(driver, device, container, options, primary);
48 } else if ( strcmp(driver, "wav") == 0 ) {
49  return sources_add_wav(driver, device, container, options, primary);
50 } else if ( strcmp(driver, "cf") == 0 ) {
51  return sources_add_cf(driver, device, container, options, primary);
52 } else if ( strcmp(driver, "roar") == 0 ) {
53  return sources_add_roar(driver, device, container, options, primary);
54 }
55
56 return -1;
57}
58
59int sources_add_raw (char * driver, char * device, char * container, char * options, int primary) {
60 int stream;
61 int fh;
62 struct roar_stream * s;
63
64 ROAR_WARN("sources_add_raw(*): The raw source is obsolete, use source 'cf' (default)!");
65
66 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
67  return -1;
68 }
69
70 if ( (stream = streams_new()) == -1 ) {
71  close(fh);
72  return -1;
73 }
74
75 streams_get(stream, (struct roar_stream_server **)&s);
76
77 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
78
79 s->dir        = ROAR_DIR_PLAY;
80 s->pos_rel_id = -1;
81
82 streams_set_fh(stream, fh);
83
84 client_stream_add(g_source_client, stream);
85
86 return 0;
87}
88
89int sources_add_wav (char * driver, char * device, char * container, char * options, int primary) {
90 int stream;
91 int fh;
92 char buf[44];
93 struct roar_stream * s;
94
95 ROAR_WARN("sources_add_raw(*): The wav(e) source is obsolete, use source 'cf' (default)!");
96
97 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
98  return -1;
99 }
100
101 if (read(fh, buf, 44) != 44) {
102  close(fh);
103  return -1;
104 }
105
106 if ( (stream = streams_new()) == -1 ) {
107  close(fh);
108  return -1;
109 }
110
111 streams_get(stream, (struct roar_stream_server **)&s);
112
113 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
114
115  memcpy(&(s->info.rate    ), buf+24, 4);
116  memcpy(&(s->info.channels), buf+22, 2);
117  memcpy(&(s->info.bits    ), buf+34, 2);
118
119 s->dir        = ROAR_DIR_PLAY;
120 s->pos_rel_id = -1;
121
122 streams_set_fh(stream, fh);
123
124 client_stream_add(g_source_client, stream);
125
126 return 0;
127}
128
129int sources_add_cf (char * driver, char * device, char * container, char * options, int primary) {
130 int  stream;
131 int  fh;
132 int  codec;
133 int  len;
134 char buf[64];
135 struct roar_stream * s;
136
137 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
138  return -1;
139 }
140
141 // TODO: finy out a better way of doing auto detetion without need for seek!
142 if ( !options ) {
143  if ( (len = read(fh, buf, 64)) < 1 ) {
144   close(fh);
145   return -1;
146  }
147
148  if ( lseek(fh, -len, SEEK_CUR) == (off_t)-1 ) {
149   close(fh);
150   return -1;
151  }
152
153  if ( (codec = roar_file_codecdetect(buf, len)) == -1 ) {
154   close(fh);
155   return -1;
156  }
157 } else {
158  if ( (codec = roar_str2codec(options)) == -1 ) {
159   close(fh);
160   return -1;
161  }
162 }
163
164 if ( (stream = streams_new()) == -1 ) {
165  close(fh);
166  return -1;
167 }
168
169 streams_get(stream, (struct roar_stream_server **)&s);
170
171 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
172
173 s->dir        = ROAR_DIR_PLAY;
174 s->pos_rel_id = -1;
175 s->info.codec = codec;
176
177 ROAR_STREAM_SERVER(s)->codec_orgi = codec;
178
179 streams_set_fh(stream, fh);
180 streams_set_socktype(stream, ROAR_SOCKET_TYPE_FILE);
181
182 if ( primary )
183  streams_mark_primary(stream);
184
185 client_stream_add(g_source_client, stream);
186
187 return 0;
188}
189
190int sources_add_roar (char * driver, char * device, char * container, char * options, int primary) {
191 int  stream;
192 int  fh;
193 int  codec = ROAR_CODEC_DEFAULT;
194 struct roar_stream * s;
195
196 if ( options != NULL && *options ) {
197  if ( (codec = roar_str2codec(options)) == -1 ) {
198   return -1;
199  }
200 }
201
202 if ( (fh = roar_simple_monitor(g_sa->rate, g_sa->channels, g_sa->bits, codec, device, "roard")) == -1 ) {
203  return -1;
204 }
205
206 if ( (stream = streams_new()) == -1 ) {
207  close(fh);
208  return -1;
209 }
210
211 streams_get(stream, (struct roar_stream_server **)&s);
212
213 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
214
215 s->dir        = ROAR_DIR_PLAY;
216 s->pos_rel_id = -1;
217 s->info.codec = codec;
218
219 ROAR_STREAM_SERVER(s)->codec_orgi = codec;
220
221 streams_set_fh(stream, fh);
222
223 if ( primary )
224  streams_mark_primary(stream);
225
226 client_stream_add(g_source_client, stream);
227
228 return 0;
229}
230
231//ll
Note: See TracBrowser for help on using the repository browser.