source: roaraudio/roard/driver.c @ 919:0d97efb0782c

Last change on this file since 919:0d97efb0782c was 919:0d97efb0782c, checked in by phi, 15 years ago

wrote working(!) OSS driver

File size: 4.3 KB
Line 
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
27struct roar_driver g_driver[] = {
28 { "null", "null audio driver", "/dev/null", NULL, NULL, NULL, NULL, NULL, NULL, NULL},
29#ifdef ROAR_HAVE_ESD
30 { "esd", "EsounD audio driver", "localhost, remote.host.dom", NULL, driver_esd_close, driver_esd_pause, NULL, NULL, driver_esd_flush, driver_esd_open_vio},
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, NULL},
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, NULL},
34#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
35 { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, NULL, driver_oss_close, NULL, NULL, NULL, NULL, driver_oss_open},
36#endif
37#ifdef ROAR_HAVE_LIBAO
38 { "ao", "libao audio driver", "DRIVER", driver_ao_open, driver_ao_close, driver_ao_pause, driver_ao_write, driver_ao_read, driver_ao_flush, NULL},
39#endif
40 {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list
41                                };
42
43void print_driverlist (void) {
44 int i;
45
46 for (i = 0; g_driver[i].name != NULL; i++) {
47  printf("  %-8s - %s (devices: %s)\n", g_driver[i].name, g_driver[i].desc, g_driver[i].devices);
48 }
49}
50
51int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) {
52 int i;
53
54 if ( driver == NULL )
55  driver = ROAR_DRIVER_DEFAULT;
56
57 for (i = 0; g_driver[i].name != NULL; i++) {
58  if ( strcmp(g_driver[i].name, driver) == 0 ) {
59   ROAR_DBG("driver_open(*): found driver: id = %i", i);
60
61   *driver_id = i;
62
63   if ( g_driver[i].vio_init != NULL ) {
64    if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL )
65     return -1;
66
67    memset(*inst, 0, sizeof(struct roar_vio_calls));
68
69    if ( (i = g_driver[i].vio_init(*inst, device, info)) == -1 ) {
70     free(*inst);
71     return -1;
72    }
73    return i;
74   }
75
76   ROAR_WARN("driver_open(*): driver uses old non-vio interface!");
77
78   if ( g_driver[i].open )
79    return g_driver[i].open(inst, device, info);
80   return 0;
81  }
82 }
83
84 return -1;
85}
86
87int driver_close(DRIVER_USERDATA_T   inst, int driver) {
88 int ret = 0;
89 ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver);
90
91 if ( driver == -1 )
92  return -1;
93
94 if ( g_driver[driver].close )
95  ret = g_driver[driver].close(inst);
96
97 if ( g_driver[driver].vio_init != NULL )
98  free(inst);
99
100 return ret;
101}
102
103int driver_pause(DRIVER_USERDATA_T   inst, int driver, int newstate) {
104 if ( driver == -1 )
105  return -1;
106
107 if ( g_driver[driver].pause )
108  return g_driver[driver].pause(inst, newstate);
109
110 return 0;
111}
112
113int driver_write(DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
114 if ( driver == -1 )
115  return -1;
116
117 if ( g_driver[driver].vio_init != NULL )
118  return roar_vio_write((struct roar_vio_calls *) inst, buf, len);
119
120 if ( g_driver[driver].write )
121  return g_driver[driver].write(inst, buf, len);
122
123 return 0;
124}
125
126int driver_read (DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
127 if ( driver == -1 )
128  return -1;
129
130 if ( g_driver[driver].vio_init != NULL )
131  return roar_vio_read((struct roar_vio_calls *) inst, buf, len);
132
133 if ( g_driver[driver].read )
134  return g_driver[driver].read(inst, buf, len);
135
136 return 0;
137}
138
139int driver_flush(DRIVER_USERDATA_T   inst, int driver) {
140 if ( driver == -1 )
141  return -1;
142
143 if ( g_driver[driver].flush )
144  return g_driver[driver].flush(inst);
145
146 return 0;
147}
148
149//ll
Note: See TracBrowser for help on using the repository browser.