source: roaraudio/roard/sources.c @ 706:6627e0732b98

Last change on this file since 706:6627e0732b98 was 668:71ac426690da, checked in by phi, 16 years ago

added license statements

File size: 4.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 }
53
54 return -1;
55}
56
57int sources_add_raw (char * driver, char * device, char * container, char * options, int primary) {
58 int stream;
59 int fh;
60 struct roar_stream * s;
61
62 ROAR_WARN("sources_add_raw(*): The raw source is obsolete, use source 'cf' (default)!");
63
64 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
65  return -1;
66 }
67
68 if ( (stream = streams_new()) == -1 ) {
69  close(fh);
70  return -1;
71 }
72
73 streams_get(stream, (struct roar_stream_server **)&s);
74
75 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
76
77 s->dir        = ROAR_DIR_PLAY;
78 s->pos_rel_id = -1;
79
80 streams_set_fh(stream, fh);
81
82 client_stream_add(g_source_client, stream);
83
84 return 0;
85}
86
87int sources_add_wav (char * driver, char * device, char * container, char * options, int primary) {
88 int stream;
89 int fh;
90 char buf[44];
91 struct roar_stream * s;
92
93 ROAR_WARN("sources_add_raw(*): The wav(e) source is obsolete, use source 'cf' (default)!");
94
95 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
96  return -1;
97 }
98
99 if (read(fh, buf, 44) != 44) {
100  close(fh);
101  return -1;
102 }
103
104 if ( (stream = streams_new()) == -1 ) {
105  close(fh);
106  return -1;
107 }
108
109 streams_get(stream, (struct roar_stream_server **)&s);
110
111 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
112
113  memcpy(&(s->info.rate    ), buf+24, 4);
114  memcpy(&(s->info.channels), buf+22, 2);
115  memcpy(&(s->info.bits    ), buf+34, 2);
116
117 s->dir        = ROAR_DIR_PLAY;
118 s->pos_rel_id = -1;
119
120 streams_set_fh(stream, fh);
121
122 client_stream_add(g_source_client, stream);
123
124 return 0;
125}
126
127int sources_add_cf (char * driver, char * device, char * container, char * options, int primary) {
128 int  stream;
129 int  fh;
130 int  codec;
131 int  len;
132 char buf[64];
133 struct roar_stream * s;
134
135 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
136  return -1;
137 }
138
139 // TODO: finy out a better way of doing auto detetion without need for seek!
140 if ( !options ) {
141  if ( (len = read(fh, buf, 64)) < 1 ) {
142   close(fh);
143   return -1;
144  }
145
146  if ( lseek(fh, -len, SEEK_CUR) == (off_t)-1 ) {
147   close(fh);
148   return -1;
149  }
150
151  if ( (codec = roar_file_codecdetect(buf, len)) == -1 ) {
152   close(fh);
153   return -1;
154  }
155 } else {
156  if ( (codec = roar_str2codec(options)) == -1 ) {
157   close(fh);
158   return -1;
159  }
160 }
161
162 if ( (stream = streams_new()) == -1 ) {
163  close(fh);
164  return -1;
165 }
166
167 streams_get(stream, (struct roar_stream_server **)&s);
168
169 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
170
171 s->dir        = ROAR_DIR_PLAY;
172 s->pos_rel_id = -1;
173 s->info.codec = codec;
174
175 ROAR_STREAM_SERVER(s)->codec_orgi = codec;
176
177 streams_set_fh(stream, fh);
178 streams_set_socktype(stream, ROAR_SOCKET_TYPE_FILE);
179
180 if ( primary )
181  streams_mark_primary(stream);
182
183 client_stream_add(g_source_client, stream);
184
185 return 0;
186}
187
188//ll
Note: See TracBrowser for help on using the repository browser.