[468] | 1 | //roar.c: |
---|
| 2 | |
---|
[703] | 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[4042] | 5 | * Copyright (C) 2000-2003 the xine project |
---|
[703] | 6 | * |
---|
| 7 | * This file is part of the xine RoarAudio plugin a part of RoarAudio, |
---|
| 8 | * a cross-platform sound system for both, home and professional use. |
---|
| 9 | * See README for details. |
---|
| 10 | * |
---|
| 11 | * This file is free software; you can redistribute it and/or modify |
---|
| 12 | * it under the terms of the GNU General Public License version 3 |
---|
| 13 | * as published by the Free Software Foundation. |
---|
| 14 | * |
---|
| 15 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | * GNU General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 22 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 23 | * Boston, MA 02110-1301, USA. |
---|
[703] | 24 | * |
---|
| 25 | */ |
---|
| 26 | |
---|
[3055] | 27 | #include <roaraudio.h> |
---|
[468] | 28 | #include <stdio.h> |
---|
| 29 | #include <stdlib.h> |
---|
| 30 | #include <errno.h> |
---|
| 31 | #include <string.h> |
---|
[3055] | 32 | #ifdef ROAR_HAVE_H_UNISTD |
---|
[468] | 33 | #include <unistd.h> |
---|
[3055] | 34 | #endif |
---|
| 35 | #ifdef ROAR_HAVE_H_SIGNAL |
---|
[468] | 36 | #include <signal.h> |
---|
[3055] | 37 | #endif |
---|
[468] | 38 | #include <sys/time.h> |
---|
| 39 | #include <sys/uio.h> |
---|
| 40 | #include <inttypes.h> |
---|
| 41 | |
---|
| 42 | #include <xine/xine_internal.h> |
---|
| 43 | #include <xine/xineutils.h> |
---|
| 44 | #include <xine/audio_out.h> |
---|
| 45 | #include <xine/metronom.h> |
---|
| 46 | |
---|
[469] | 47 | #define AO_OUT_ROAR_IFACE_VERSION 8 |
---|
[468] | 48 | |
---|
| 49 | #define GAP_TOLERANCE 5000 |
---|
| 50 | |
---|
| 51 | typedef struct esd_driver_s { |
---|
| 52 | ao_driver_t ao_driver; |
---|
| 53 | |
---|
| 54 | xine_t *xine; |
---|
| 55 | |
---|
| 56 | int capabilities; |
---|
| 57 | |
---|
| 58 | struct roar_connection con; |
---|
| 59 | struct roar_stream stream; |
---|
| 60 | int fh; |
---|
| 61 | |
---|
| 62 | } roar_driver_t; |
---|
| 63 | |
---|
| 64 | typedef struct { |
---|
| 65 | audio_driver_class_t driver_class; |
---|
| 66 | xine_t *xine; |
---|
| 67 | } roar_class_t; |
---|
| 68 | |
---|
| 69 | static int ao_roar_open(ao_driver_t *this_gen, |
---|
| 70 | uint32_t bits, uint32_t rate, int mode) { |
---|
| 71 | return -1; |
---|
| 72 | } |
---|
| 73 | static void ao_roar_close(ao_driver_t *this_gen) { |
---|
| 74 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
| 75 | |
---|
| 76 | if ( this->fh != -1 ) |
---|
| 77 | close(this->fh); |
---|
| 78 | this->fh = -1; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | static int ao_roar_num_channels(ao_driver_t *this_gen) { |
---|
| 82 | return -1; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | static int ao_roar_bytes_per_frame(ao_driver_t *this_gen) { |
---|
| 86 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
| 87 | return (this->stream.info.bits * this->stream.info.channels)/8; |
---|
| 88 | } |
---|
[469] | 89 | |
---|
[468] | 90 | static int ao_roar_delay(ao_driver_t *this_gen) { |
---|
[469] | 91 | return 0; |
---|
[468] | 92 | } |
---|
[469] | 93 | |
---|
[468] | 94 | static int ao_roar_write(ao_driver_t *this_gen, |
---|
| 95 | int16_t* frame_buffer, uint32_t num_frames) { |
---|
| 96 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
| 97 | int bpf = (this->stream.info.bits * this->stream.info.channels)/8; |
---|
| 98 | return write(this->fh, frame_buffer, num_frames*bpf) / bpf; |
---|
| 99 | } |
---|
| 100 | static int ao_roar_get_gap_tolerance (ao_driver_t *this_gen) { |
---|
| 101 | return GAP_TOLERANCE; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | static void ao_roar_exit(ao_driver_t *this_gen) { |
---|
| 105 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
| 106 | |
---|
| 107 | ao_roar_close(this_gen); |
---|
| 108 | |
---|
| 109 | roar_disconnect(&(this->con)); |
---|
| 110 | |
---|
| 111 | free(this); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | static int ao_roar_get_property (ao_driver_t *this_gen, int property) { |
---|
[469] | 115 | return 0; |
---|
[468] | 116 | } |
---|
| 117 | static int ao_roar_set_property (ao_driver_t *this_gen, int property, int value) { |
---|
[469] | 118 | return ~value; |
---|
[468] | 119 | } |
---|
| 120 | |
---|
| 121 | static int ao_roar_ctrl(ao_driver_t *this_gen, int cmd, ...) { |
---|
| 122 | return 0; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | static uint32_t ao_roar_get_capabilities (ao_driver_t *this_gen) { |
---|
| 126 | roar_driver_t *this = (roar_driver_t *) this_gen; |
---|
| 127 | return this->capabilities; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, |
---|
| 131 | const void *data) { |
---|
| 132 | roar_driver_t *this; |
---|
| 133 | |
---|
| 134 | this = (roar_driver_t *) xine_xmalloc(sizeof(roar_driver_t)); |
---|
| 135 | if ( !this ) |
---|
| 136 | return NULL; |
---|
| 137 | |
---|
| 138 | if ( roar_simple_connect(&(this->con), NULL, "libxine") == -1 ) { |
---|
| 139 | free(this); |
---|
| 140 | return NULL; |
---|
| 141 | } |
---|
| 142 | |
---|
[469] | 143 | this->fh = -1; |
---|
| 144 | |
---|
[468] | 145 | this->capabilities = AO_CAP_MODE_MONO | AO_CAP_MODE_STEREO | AO_CAP_MIXER_VOL | AO_CAP_MUTE_VOL; |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | this->ao_driver.get_capabilities = ao_roar_get_capabilities; |
---|
| 149 | this->ao_driver.get_property = ao_roar_get_property; |
---|
| 150 | this->ao_driver.set_property = ao_roar_set_property; |
---|
| 151 | this->ao_driver.open = ao_roar_open; |
---|
| 152 | this->ao_driver.num_channels = ao_roar_num_channels; |
---|
| 153 | this->ao_driver.bytes_per_frame = ao_roar_bytes_per_frame; |
---|
| 154 | this->ao_driver.get_gap_tolerance = ao_roar_get_gap_tolerance; |
---|
| 155 | this->ao_driver.delay = ao_roar_delay; |
---|
| 156 | this->ao_driver.write = ao_roar_write; |
---|
| 157 | this->ao_driver.close = ao_roar_close; |
---|
| 158 | this->ao_driver.exit = ao_roar_exit; |
---|
| 159 | this->ao_driver.control = ao_roar_ctrl; |
---|
| 160 | |
---|
| 161 | return &(this->ao_driver); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | static char* get_identifier (audio_driver_class_t *this_gen) { |
---|
| 166 | return "roar"; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | static char* get_description (audio_driver_class_t *this_gen) { |
---|
| 170 | return _("xine audio output plugin using RoarAudio"); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | static void dispose_class (audio_driver_class_t *this_gen) { |
---|
| 174 | |
---|
| 175 | roar_class_t *this = (roar_class_t *) this_gen; |
---|
| 176 | |
---|
| 177 | free (this); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | static void *init_class (xine_t *xine, void *data) { |
---|
| 181 | |
---|
| 182 | roar_class_t *this; |
---|
| 183 | |
---|
| 184 | this = (roar_class_t *) xine_xmalloc(sizeof(roar_class_t)); |
---|
| 185 | |
---|
| 186 | this->driver_class.open_plugin = open_plugin; |
---|
| 187 | this->driver_class.get_identifier = get_identifier; |
---|
| 188 | this->driver_class.get_description = get_description; |
---|
| 189 | this->driver_class.dispose = dispose_class; |
---|
| 190 | |
---|
| 191 | this->xine = xine; |
---|
| 192 | |
---|
| 193 | return this; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | static const ao_info_t ao_info_roar = { |
---|
| 197 | 4 |
---|
| 198 | }; |
---|
| 199 | |
---|
| 200 | const plugin_info_t xine_plugin_info[] = { |
---|
| 201 | /* type, API, "name", version, special_info, init_function */ |
---|
| 202 | { PLUGIN_AUDIO_OUT, AO_OUT_ROAR_IFACE_VERSION, "roar", XINE_VERSION_CODE, &ao_info_roar, init_class }, |
---|
| 203 | { PLUGIN_NONE, 0, "", 0, NULL, NULL } |
---|
| 204 | }; |
---|
| 205 | |
---|
| 206 | //ll |
---|