source: roaraudio/roard/sources.c @ 542:c71495eebd20

Last change on this file since 542:c71495eebd20 was 542:c71495eebd20, checked in by phi, 16 years ago

added sources_add_cf()

File size: 2.6 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 struct roar_stream * s;
106
107 if ( (codec = roar_str2codec(options)) == -1 )
108  return -1;
109
110 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
111  return -1;
112 }
113
114 if ( (stream = streams_new()) == -1 ) {
115  close(fh);
116  return -1;
117 }
118
119 streams_get(stream, (struct roar_stream_server **)&s);
120
121 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
122
123 s->dir        = ROAR_DIR_PLAY;
124 s->pos_rel_id = -1;
125 s->info.codec = codec;
126
127 streams_set_fh(stream, fh);
128
129 client_stream_add(g_source_client, stream);
130
131 return 0;
132}
133
134//ll
Note: See TracBrowser for help on using the repository browser.