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