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