1 | /* |
---|
2 | * |
---|
3 | * ao_roar.c |
---|
4 | * |
---|
5 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
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 | 50, |
---|
61 | ao_roar_options, |
---|
62 | 1 |
---|
63 | }; |
---|
64 | |
---|
65 | |
---|
66 | typedef struct ao_roar_internal { |
---|
67 | struct roar_vio_calls svio; |
---|
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 | #ifdef HAVE_MATRIX |
---|
122 | char * map = NULL; |
---|
123 | #endif |
---|
124 | |
---|
125 | if ( roar_vio_simple_stream(&(internal->svio), format->rate, format->channels, format->bits, |
---|
126 | ROAR_CODEC_DEFAULT, internal->host, ROAR_DIR_PLAY, "libao client") == -1 ) |
---|
127 | return 0; |
---|
128 | |
---|
129 | device->driver_byte_format = AO_FMT_NATIVE; |
---|
130 | |
---|
131 | #ifdef HAVE_MATRIX |
---|
132 | if( device->output_matrix != NULL ) |
---|
133 | free(device->output_matrix); |
---|
134 | |
---|
135 | device->output_matrix = NULL; |
---|
136 | |
---|
137 | switch (format->channels) { |
---|
138 | case 1: map = "M"; break; |
---|
139 | case 2: map = "L,R"; break; |
---|
140 | case 3: map = "L,R,C"; break; |
---|
141 | case 4: map = "L,R,BL,BR"; break; |
---|
142 | case 5: map = "L,R,C,BL,BR"; break; |
---|
143 | case 6: map = "L,R,C,LFE,BL,BR"; break; |
---|
144 | } |
---|
145 | |
---|
146 | if ( map != NULL ) |
---|
147 | device->output_matrix = strdup(map); |
---|
148 | #endif |
---|
149 | |
---|
150 | return 1; |
---|
151 | } |
---|
152 | |
---|
153 | int ao_plugin_play(ao_device * device, const char * output_samples, uint_32 num_bytes) { |
---|
154 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
155 | |
---|
156 | if (roar_vio_write(&(internal->svio), (char*)output_samples, num_bytes) == -1) { |
---|
157 | return 0; |
---|
158 | } else { |
---|
159 | return 1; |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | int ao_plugin_close(ao_device * device) { |
---|
165 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
166 | |
---|
167 | roar_vio_close(&(internal->svio)); |
---|
168 | |
---|
169 | return 1; |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | void ao_plugin_device_clear(ao_device * device) { |
---|
174 | ao_roar_internal * internal = (ao_roar_internal *) device->internal; |
---|
175 | |
---|
176 | if( internal->host != NULL ) |
---|
177 | free(internal->host); |
---|
178 | |
---|
179 | free(internal); |
---|
180 | } |
---|