1 | //driver.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 | |
---|
27 | struct roar_driver g_driver[] = { |
---|
28 | { "null", "null audio driver", "/dev/null", NULL, NULL, NULL, NULL, NULL, NULL}, |
---|
29 | #ifdef ROAR_HAVE_ESD |
---|
30 | { "esd", "EsounD audio driver", "localhost, remote.host.dom", driver_esd_open, driver_esd_close, driver_esd_pause, driver_esd_write, driver_esd_read, driver_esd_flush}, |
---|
31 | #endif |
---|
32 | { "roar", "RoarAudio driver", "localhost, remote.host.dom", driver_roar_open, driver_roar_close, driver_roar_pause, driver_roar_write, driver_roar_read, driver_roar_flush}, |
---|
33 | { "raw", "RAW PCM driver", "/some/file", driver_raw_open, driver_raw_close, driver_roar_pause, driver_raw_write, driver_raw_read, driver_raw_flush}, |
---|
34 | #ifdef ROAR_HAVE_LIBAO |
---|
35 | { "ao", "libao audio driver", "DRIVER", driver_ao_open, driver_ao_close, driver_ao_pause, driver_ao_write, driver_ao_read, driver_ao_flush}, |
---|
36 | #endif |
---|
37 | {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list |
---|
38 | }; |
---|
39 | |
---|
40 | void print_driverlist (void) { |
---|
41 | int i; |
---|
42 | |
---|
43 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
44 | printf(" %-8s - %s (devices: %s)\n", g_driver[i].name, g_driver[i].desc, g_driver[i].devices); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) { |
---|
49 | int i; |
---|
50 | |
---|
51 | if ( driver == NULL ) |
---|
52 | driver = ROAR_DRIVER_DEFAULT; |
---|
53 | |
---|
54 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
55 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
56 | ROAR_DBG("driver_open(*): found driver: id = %i", i); |
---|
57 | |
---|
58 | *driver_id = i; |
---|
59 | |
---|
60 | if ( g_driver[i].open ) |
---|
61 | return g_driver[i].open(inst, device, info); |
---|
62 | return 0; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | return -1; |
---|
67 | } |
---|
68 | |
---|
69 | int driver_close(DRIVER_USERDATA_T inst, int driver) { |
---|
70 | ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver); |
---|
71 | |
---|
72 | if ( driver == -1 ) |
---|
73 | return -1; |
---|
74 | |
---|
75 | if ( g_driver[driver].close ) |
---|
76 | return g_driver[driver].close(inst); |
---|
77 | |
---|
78 | return 0; |
---|
79 | } |
---|
80 | |
---|
81 | int driver_pause(DRIVER_USERDATA_T inst, int driver, int newstate) { |
---|
82 | if ( driver == -1 ) |
---|
83 | return -1; |
---|
84 | |
---|
85 | if ( g_driver[driver].pause ) |
---|
86 | return g_driver[driver].pause(inst, newstate); |
---|
87 | |
---|
88 | return 0; |
---|
89 | } |
---|
90 | |
---|
91 | int driver_write(DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
92 | if ( driver == -1 ) |
---|
93 | return -1; |
---|
94 | |
---|
95 | if ( g_driver[driver].write ) |
---|
96 | return g_driver[driver].write(inst, buf, len); |
---|
97 | |
---|
98 | return 0; |
---|
99 | } |
---|
100 | |
---|
101 | int driver_read (DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
102 | if ( driver == -1 ) |
---|
103 | return -1; |
---|
104 | |
---|
105 | if ( g_driver[driver].read ) |
---|
106 | return g_driver[driver].read(inst, buf, len); |
---|
107 | |
---|
108 | return 0; |
---|
109 | } |
---|
110 | |
---|
111 | int driver_flush(DRIVER_USERDATA_T inst, int driver) { |
---|
112 | if ( driver == -1 ) |
---|
113 | return -1; |
---|
114 | |
---|
115 | if ( g_driver[driver].flush ) |
---|
116 | return g_driver[driver].flush(inst); |
---|
117 | |
---|
118 | return 0; |
---|
119 | } |
---|
120 | |
---|
121 | //ll |
---|