subs: move text sub loading logic down to find_subfiles.c
[mplayer/greg.git] / libao2 / audio_out.c
blobd1887c223caebfb7b03e521e91cf282c856d3fd4
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <assert.h>
24 #include "config.h"
25 #include "audio_out.h"
27 #include "mp_msg.h"
29 // there are some globals:
30 struct ao ao_data;
31 char *ao_subdevice = NULL;
33 extern const ao_functions_t audio_out_oss;
34 extern const ao_functions_t audio_out_coreaudio;
35 extern const ao_functions_t audio_out_arts;
36 extern const ao_functions_t audio_out_esd;
37 extern const ao_functions_t audio_out_pulse;
38 extern const ao_functions_t audio_out_jack;
39 extern const ao_functions_t audio_out_openal;
40 extern const ao_functions_t audio_out_null;
41 extern const ao_functions_t audio_out_alsa5;
42 extern const ao_functions_t audio_out_alsa;
43 extern const ao_functions_t audio_out_nas;
44 extern const ao_functions_t audio_out_sdl;
45 extern const ao_functions_t audio_out_sun;
46 extern const ao_functions_t audio_out_sgi;
47 extern const ao_functions_t audio_out_win32;
48 extern const ao_functions_t audio_out_dsound;
49 extern const ao_functions_t audio_out_kai;
50 extern const ao_functions_t audio_out_dart;
51 extern const ao_functions_t audio_out_ivtv;
52 extern const ao_functions_t audio_out_v4l2;
53 extern const ao_functions_t audio_out_mpegpes;
54 extern const ao_functions_t audio_out_pcm;
55 extern const ao_functions_t audio_out_pss;
57 const ao_functions_t* const audio_out_drivers[] =
59 // native:
60 #ifdef CONFIG_DIRECTX
61 &audio_out_dsound,
62 #endif
63 #ifdef CONFIG_WIN32WAVEOUT
64 &audio_out_win32,
65 #endif
66 #ifdef CONFIG_KAI
67 &audio_out_kai,
68 #endif
69 #ifdef CONFIG_DART
70 &audio_out_dart,
71 #endif
72 #ifdef CONFIG_COREAUDIO
73 &audio_out_coreaudio,
74 #endif
75 #ifdef CONFIG_OSS_AUDIO
76 &audio_out_oss,
77 #endif
78 #ifdef CONFIG_ALSA
79 &audio_out_alsa,
80 #endif
81 #ifdef CONFIG_ALSA5
82 &audio_out_alsa5,
83 #endif
84 #ifdef CONFIG_SGI_AUDIO
85 &audio_out_sgi,
86 #endif
87 #ifdef CONFIG_SUN_AUDIO
88 &audio_out_sun,
89 #endif
90 // wrappers:
91 #ifdef CONFIG_ARTS
92 &audio_out_arts,
93 #endif
94 #ifdef CONFIG_ESD
95 &audio_out_esd,
96 #endif
97 #ifdef CONFIG_PULSE
98 &audio_out_pulse,
99 #endif
100 #ifdef CONFIG_JACK
101 &audio_out_jack,
102 #endif
103 #ifdef CONFIG_NAS
104 &audio_out_nas,
105 #endif
106 #ifdef CONFIG_SDL
107 &audio_out_sdl,
108 #endif
109 #ifdef CONFIG_OPENAL
110 &audio_out_openal,
111 #endif
112 &audio_out_mpegpes,
113 #ifdef CONFIG_IVTV
114 &audio_out_ivtv,
115 #endif
116 #ifdef CONFIG_V4L2_DECODER
117 &audio_out_v4l2,
118 #endif
119 &audio_out_null,
120 // should not be auto-selected:
121 &audio_out_pcm,
122 NULL
125 void list_audio_out(void){
126 int i=0;
127 mp_tmsg(MSGT_AO, MSGL_INFO, "Available audio output drivers:\n");
128 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_OUTPUTS\n");
129 while (audio_out_drivers[i]) {
130 const ao_info_t *info = audio_out_drivers[i++]->info;
131 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
133 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
136 struct ao *ao_create(void)
138 ao_data = (struct ao){.outburst = OUTBURST, .buffersize = -1};
139 return &ao_data;
142 void ao_init(struct ao *ao, char **ao_list)
144 struct ao backup = *ao;
146 if (!ao_list)
147 goto try_defaults;
149 // first try the preferred drivers, with their optional subdevice param:
150 while (*ao_list) {
151 char *ao_name = *ao_list;
152 if (!*ao_name)
153 goto try_defaults; // empty entry means try defaults
154 int ao_len;
155 assert(!ao_subdevice);
156 ao_subdevice = strchr(ao_name, ':');
157 if (ao_subdevice) {
158 ao_len = ao_subdevice - ao_name;
159 ao_subdevice = strdup(ao_subdevice + 1);
160 } else
161 ao_len = strlen(ao_name);
163 mp_tmsg(MSGT_AO, MSGL_V,
164 "Trying preferred audio driver '%.*s', options '%s'\n",
165 ao_len, ao_name, ao_subdevice ? ao_subdevice : "[none]");
167 const ao_functions_t *audio_out = NULL;
168 for (int i = 0; audio_out_drivers[i]; i++) {
169 audio_out = audio_out_drivers[i];
170 if (!strncmp(audio_out->info->short_name, ao_name, ao_len))
171 break;
172 audio_out = NULL;
174 if (audio_out) {
175 // name matches, try it
176 if (audio_out->init(ao->samplerate, ao->channels, ao->format, 0)) {
177 ao->driver = audio_out;
178 ao->initialized = true;
179 return;
181 mp_tmsg(MSGT_AO, MSGL_WARN,
182 "Failed to initialize audio driver '%s'\n", ao_name);
183 *ao = backup;
184 } else
185 mp_tmsg(MSGT_AO, MSGL_WARN, "No such audio driver '%.*s'\n",
186 ao_len, ao_name);
187 free(ao_subdevice);
188 ao_subdevice = NULL;
189 ++ao_list;
191 return;
193 try_defaults:
194 mp_tmsg(MSGT_AO, MSGL_V, "Trying every known audio driver...\n");
196 // now try the rest...
197 for (int i = 0; audio_out_drivers[i]; i++) {
198 const ao_functions_t *audio_out = audio_out_drivers[i];
199 if (audio_out->init(ao->samplerate, ao->channels, ao->format, 0)) {
200 ao->initialized = true;
201 ao->driver = audio_out;
202 return;
204 *ao = backup;
206 return;
209 void ao_uninit(struct ao *ao, bool drain_audio)
211 if (ao->initialized)
212 ao->driver->uninit(drain_audio);
213 ao->initialized = false;
214 free(ao_subdevice);
215 ao_subdevice = NULL;
218 int ao_play(struct ao *ao, void *data, int len, int flags)
220 return ao->driver->play(data, len, flags);
223 int ao_control(struct ao *ao, int cmd, void *arg)
225 return ao->driver->control(cmd, arg);
228 double ao_get_delay(struct ao *ao)
230 return ao->driver->get_delay();
233 int ao_get_space(struct ao *ao)
235 return ao->driver->get_space();
238 void ao_reset(struct ao *ao)
240 ao->driver->reset();
243 void ao_pause(struct ao *ao)
245 ao->driver->pause();
248 void ao_resume(struct ao *ao)
250 ao->driver->resume();