[0] | 1 | /* |
---|
| 2 | * |
---|
| 3 | * ao_roar.c |
---|
| 4 | * |
---|
| 5 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - May 2008 |
---|
| 6 | * based on ao_esd.c of libao by Stan Seibert - July 2000, July 2001 |
---|
| 7 | * |
---|
| 8 | * This file is part of RoarAudio, a cross-platform sound server. See |
---|
| 9 | * README for a history of this source code. |
---|
| 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 as published by |
---|
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
---|
| 14 | * any later version. |
---|
| 15 | * |
---|
| 16 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 19 | * GNU General Public License for more details. |
---|
| 20 | * |
---|
| 21 | * You should have received a copy of the GNU General Public License |
---|
| 22 | * along with GNU Make; see the file COPYING. If not, write to |
---|
| 23 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 24 | * |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #include <stdio.h> |
---|
| 28 | #include <unistd.h> |
---|
| 29 | #include <stdlib.h> |
---|
| 30 | #include <string.h> |
---|
| 31 | |
---|
| 32 | #include <roaraudio.h> |
---|
| 33 | #include <ao/ao.h> |
---|
| 34 | #include <ao/plugin.h> |
---|
| 35 | |
---|
| 36 | static char * ao_roar_options[] = {"host"}; |
---|
| 37 | |
---|
| 38 | /* |
---|
| 39 | typedef struct ao_info { |
---|
| 40 | int type; // live output or file output? |
---|
| 41 | char *name; // full name of driver |
---|
| 42 | char *short_name; // short name of driver |
---|
| 43 | char *author; // driver author |
---|
| 44 | char *comment; // driver comment |
---|
| 45 | int preferred_byte_format; |
---|
| 46 | int priority; |
---|
| 47 | char **options; |
---|
| 48 | int option_count; |
---|
| 49 | } ao_info; |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | static ao_info ao_roar_info = |
---|
| 53 | { |
---|
| 54 | AO_TYPE_LIVE, |
---|
| 55 | "RoarAudio output", |
---|
| 56 | "roar", |
---|
| 57 | "Philipp 'ph3-der-loewe' Schafft, Based on code by: Stan Seibert <volsung@asu.edu>", |
---|
| 58 | "Outputs to the RoarAudio Sound Daemon.", |
---|
| 59 | AO_FMT_NATIVE, |
---|
| 60 | 41, |
---|
| 61 | ao_roar_options, |
---|
| 62 | 1 |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | typedef struct ao_roar_internal { |
---|
| 67 | int sock; |
---|
| 68 | char * host; |
---|
| 69 | } ao_roar_internal; |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | int ao_plugin_test(void) { |
---|
| 73 | struct roar_connection con; |
---|
| 74 | |
---|
| 75 | if ( roar_simple_connect(&con, NULL, "libao client") == -1 ) |
---|
| 76 | return 0; |
---|
| 77 | |
---|
| 78 | if (roar_get_standby(&con)) { |
---|
| 79 | roar_disconnect(&con); |
---|
| 80 | return 0; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | roar_disconnect(&con); |
---|
| 84 | return 1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | ao_info * ao_plugin_driver_info(void) { |
---|
| 89 | return &ao_roar_info; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | int ao_plugin_device_init(ao_device * device) { |
---|
| 94 | ao_roar_internal * internal; |
---|
| 95 | |
---|
| 96 | internal = (ao_roar_internal *) malloc(sizeof(ao_roar_internal)); |
---|
| 97 | |
---|
| 98 | if (internal == NULL) |
---|
| 99 | return 0; |
---|
| 100 | |
---|
| 101 | internal->host = NULL; |
---|
| 102 | |
---|
| 103 | device->internal = internal; |
---|
| 104 | |
---|
| 105 | return 1; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | int ao_plugin_set_option(ao_device * device, const char * key, const char * value) { |
---|
| 109 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
| 110 | |
---|
| 111 | if ( strcmp(key, "host") == 0 ) { |
---|
| 112 | if(internal->host) free(internal->host); |
---|
| 113 | internal->host = strdup(value); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | return 1; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | int ao_plugin_open(ao_device * device, ao_sample_format * format) { |
---|
| 120 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
| 121 | |
---|
| 122 | internal->sock = roar_simple_play(format->rate, format->channels, format->bits, |
---|
| 123 | ROAR_CODEC_DEFAULT, internal->host, "libao client"); |
---|
| 124 | |
---|
| 125 | if ( internal->sock == -1 ) |
---|
| 126 | return 0; |
---|
| 127 | |
---|
| 128 | device->driver_byte_format = AO_FMT_NATIVE; |
---|
| 129 | |
---|
| 130 | return 1; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | int ao_plugin_play(ao_device * device, const char * output_samples, uint_32 num_bytes) { |
---|
| 134 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
| 135 | |
---|
| 136 | if (write(internal->sock, output_samples, num_bytes) == -1) { |
---|
| 137 | return 0; |
---|
| 138 | } else { |
---|
| 139 | return 1; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | int ao_plugin_close(ao_device * device) { |
---|
| 145 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
| 146 | |
---|
| 147 | roar_simple_close(internal->sock); |
---|
| 148 | |
---|
| 149 | return 1; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | void ao_plugin_device_clear(ao_device * device) { |
---|
| 154 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
| 155 | |
---|
| 156 | if( internal->host != NULL ) |
---|
| 157 | free(internal->host); |
---|
| 158 | |
---|
| 159 | free(internal); |
---|
| 160 | } |
---|