1 | //roar.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
5 | * |
---|
6 | * This file is part of the xine RoarAudio plugin 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, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include <roaraudio.h> |
---|
27 | #include <stdio.h> |
---|
28 | #include <stdlib.h> |
---|
29 | #include <errno.h> |
---|
30 | #include <string.h> |
---|
31 | #ifdef ROAR_HAVE_H_UNISTD |
---|
32 | #include <unistd.h> |
---|
33 | #endif |
---|
34 | #ifdef ROAR_HAVE_H_SIGNAL |
---|
35 | #include <signal.h> |
---|
36 | #endif |
---|
37 | #include <sys/time.h> |
---|
38 | #include <sys/uio.h> |
---|
39 | #include <inttypes.h> |
---|
40 | |
---|
41 | #include <xine/xine_internal.h> |
---|
42 | #include <xine/xineutils.h> |
---|
43 | #include <xine/audio_out.h> |
---|
44 | #include <xine/metronom.h> |
---|
45 | |
---|
46 | #define AO_OUT_ROAR_IFACE_VERSION 8 |
---|
47 | |
---|
48 | #define GAP_TOLERANCE 5000 |
---|
49 | |
---|
50 | typedef struct esd_driver_s { |
---|
51 | ao_driver_t ao_driver; |
---|
52 | |
---|
53 | xine_t *xine; |
---|
54 | |
---|
55 | int capabilities; |
---|
56 | |
---|
57 | struct roar_connection con; |
---|
58 | struct roar_stream stream; |
---|
59 | int fh; |
---|
60 | |
---|
61 | } roar_driver_t; |
---|
62 | |
---|
63 | typedef struct { |
---|
64 | audio_driver_class_t driver_class; |
---|
65 | xine_t *xine; |
---|
66 | } roar_class_t; |
---|
67 | |
---|
68 | static int ao_roar_open(ao_driver_t *this_gen, |
---|
69 | uint32_t bits, uint32_t rate, int mode) { |
---|
70 | return -1; |
---|
71 | } |
---|
72 | static void ao_roar_close(ao_driver_t *this_gen) { |
---|
73 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
74 | |
---|
75 | if ( this->fh != -1 ) |
---|
76 | close(this->fh); |
---|
77 | this->fh = -1; |
---|
78 | } |
---|
79 | |
---|
80 | static int ao_roar_num_channels(ao_driver_t *this_gen) { |
---|
81 | return -1; |
---|
82 | } |
---|
83 | |
---|
84 | static int ao_roar_bytes_per_frame(ao_driver_t *this_gen) { |
---|
85 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
86 | return (this->stream.info.bits * this->stream.info.channels)/8; |
---|
87 | } |
---|
88 | |
---|
89 | static int ao_roar_delay(ao_driver_t *this_gen) { |
---|
90 | return 0; |
---|
91 | } |
---|
92 | |
---|
93 | static int ao_roar_write(ao_driver_t *this_gen, |
---|
94 | int16_t* frame_buffer, uint32_t num_frames) { |
---|
95 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
96 | int bpf = (this->stream.info.bits * this->stream.info.channels)/8; |
---|
97 | return write(this->fh, frame_buffer, num_frames*bpf) / bpf; |
---|
98 | } |
---|
99 | static int ao_roar_get_gap_tolerance (ao_driver_t *this_gen) { |
---|
100 | return GAP_TOLERANCE; |
---|
101 | } |
---|
102 | |
---|
103 | static void ao_roar_exit(ao_driver_t *this_gen) { |
---|
104 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
105 | |
---|
106 | ao_roar_close(this_gen); |
---|
107 | |
---|
108 | roar_disconnect(&(this->con)); |
---|
109 | |
---|
110 | free(this); |
---|
111 | } |
---|
112 | |
---|
113 | static int ao_roar_get_property (ao_driver_t *this_gen, int property) { |
---|
114 | return 0; |
---|
115 | } |
---|
116 | static int ao_roar_set_property (ao_driver_t *this_gen, int property, int value) { |
---|
117 | return ~value; |
---|
118 | } |
---|
119 | |
---|
120 | static int ao_roar_ctrl(ao_driver_t *this_gen, int cmd, ...) { |
---|
121 | return 0; |
---|
122 | } |
---|
123 | |
---|
124 | static uint32_t ao_roar_get_capabilities (ao_driver_t *this_gen) { |
---|
125 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
126 | return this->capabilities; |
---|
127 | } |
---|
128 | |
---|
129 | static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, |
---|
130 | const void *data) { |
---|
131 | roar_driver_t *this; |
---|
132 | |
---|
133 | this = (roar_driver_t *) xine_xmalloc(sizeof(roar_driver_t)); |
---|
134 | if ( !this ) |
---|
135 | return NULL; |
---|
136 | |
---|
137 | if ( roar_simple_connect(&(this->con), NULL, "libxine") == -1 ) { |
---|
138 | free(this); |
---|
139 | return NULL; |
---|
140 | } |
---|
141 | |
---|
142 | this->fh = -1; |
---|
143 | |
---|
144 | this->capabilities = AO_CAP_MODE_MONO | AO_CAP_MODE_STEREO | AO_CAP_MIXER_VOL | AO_CAP_MUTE_VOL; |
---|
145 | |
---|
146 | |
---|
147 | this->ao_driver.get_capabilities = ao_roar_get_capabilities; |
---|
148 | this->ao_driver.get_property = ao_roar_get_property; |
---|
149 | this->ao_driver.set_property = ao_roar_set_property; |
---|
150 | this->ao_driver.open = ao_roar_open; |
---|
151 | this->ao_driver.num_channels = ao_roar_num_channels; |
---|
152 | this->ao_driver.bytes_per_frame = ao_roar_bytes_per_frame; |
---|
153 | this->ao_driver.get_gap_tolerance = ao_roar_get_gap_tolerance; |
---|
154 | this->ao_driver.delay = ao_roar_delay; |
---|
155 | this->ao_driver.write = ao_roar_write; |
---|
156 | this->ao_driver.close = ao_roar_close; |
---|
157 | this->ao_driver.exit = ao_roar_exit; |
---|
158 | this->ao_driver.control = ao_roar_ctrl; |
---|
159 | |
---|
160 | return &(this->ao_driver); |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | static char* get_identifier (audio_driver_class_t *this_gen) { |
---|
165 | return "roar"; |
---|
166 | } |
---|
167 | |
---|
168 | static char* get_description (audio_driver_class_t *this_gen) { |
---|
169 | return _("xine audio output plugin using RoarAudio"); |
---|
170 | } |
---|
171 | |
---|
172 | static void dispose_class (audio_driver_class_t *this_gen) { |
---|
173 | |
---|
174 | roar_class_t *this = (roar_class_t *) this_gen; |
---|
175 | |
---|
176 | free (this); |
---|
177 | } |
---|
178 | |
---|
179 | static void *init_class (xine_t *xine, void *data) { |
---|
180 | |
---|
181 | roar_class_t *this; |
---|
182 | |
---|
183 | this = (roar_class_t *) xine_xmalloc(sizeof(roar_class_t)); |
---|
184 | |
---|
185 | this->driver_class.open_plugin = open_plugin; |
---|
186 | this->driver_class.get_identifier = get_identifier; |
---|
187 | this->driver_class.get_description = get_description; |
---|
188 | this->driver_class.dispose = dispose_class; |
---|
189 | |
---|
190 | this->xine = xine; |
---|
191 | |
---|
192 | return this; |
---|
193 | } |
---|
194 | |
---|
195 | static const ao_info_t ao_info_roar = { |
---|
196 | 4 |
---|
197 | }; |
---|
198 | |
---|
199 | const plugin_info_t xine_plugin_info[] = { |
---|
200 | /* type, API, "name", version, special_info, init_function */ |
---|
201 | { PLUGIN_AUDIO_OUT, AO_OUT_ROAR_IFACE_VERSION, "roar", XINE_VERSION_CODE, &ao_info_roar, init_class }, |
---|
202 | { PLUGIN_NONE, 0, "", 0, NULL, NULL } |
---|
203 | }; |
---|
204 | |
---|
205 | //ll |
---|