source: roaraudio/roard/sources.c @ 67:9c8c096465ad

Last change on this file since 67:9c8c096465ad was 67:9c8c096465ad, checked in by phi, 16 years ago

added basic most-time-it-should-work RIFF/WAVE support to sources.c

File size: 1.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 }
29
30 return -1;
31}
32
33int sources_add_raw (char * driver, char * device, char * container, char * options, int primary) {
34 int stream;
35 int fh;
36 struct roar_stream * s;
37
38 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
39  return -1;
40 }
41
42 if ( (stream = streams_new()) == -1 ) {
43  close(fh);
44  return -1;
45 }
46
47 streams_get(stream, (struct roar_stream_server **)&s);
48
49 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
50
51 s->dir        = ROAR_DIR_PLAY;
52 s->pos_rel_id = -1;
53
54 streams_set_fh(stream, fh);
55
56 client_stream_add(g_source_client, stream);
57
58 return 0;
59}
60
61int sources_add_wav (char * driver, char * device, char * container, char * options, int primary) {
62 int stream;
63 int fh;
64 char buf[44];
65 struct roar_stream * s;
66
67 if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) {
68  return -1;
69 }
70
71 if (read(fh, buf, 44) != 44) {
72  close(fh);
73  return -1;
74 }
75
76 if ( (stream = streams_new()) == -1 ) {
77  close(fh);
78  return -1;
79 }
80
81 streams_get(stream, (struct roar_stream_server **)&s);
82
83 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
84
85  memcpy(&(s->info.rate    ), buf+24, 4);
86  memcpy(&(s->info.channels), buf+22, 2);
87  memcpy(&(s->info.bits    ), buf+34, 2);
88
89 s->dir        = ROAR_DIR_PLAY;
90 s->pos_rel_id = -1;
91
92 streams_set_fh(stream, fh);
93
94 client_stream_add(g_source_client, stream);
95
96 return 0;
97}
98//ll
Note: See TracBrowser for help on using the repository browser.