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.
27 #include "audio_out.h"
31 // there are some globals:
33 char *ao_subdevice
= NULL
;
35 extern const struct ao_driver audio_out_oss
;
36 extern const struct ao_driver audio_out_coreaudio
;
37 extern const struct ao_driver audio_out_arts
;
38 extern const struct ao_driver audio_out_rsound
;
39 extern const struct ao_driver audio_out_esd
;
40 extern const struct ao_driver audio_out_pulse
;
41 extern const struct ao_driver audio_out_jack
;
42 extern const struct ao_driver audio_out_openal
;
43 extern const struct ao_driver audio_out_null
;
44 extern const struct ao_driver audio_out_alsa
;
45 extern const struct ao_driver audio_out_nas
;
46 extern const struct ao_driver audio_out_sdl
;
47 extern const struct ao_driver audio_out_sun
;
48 extern const struct ao_driver audio_out_sgi
;
49 extern const struct ao_driver audio_out_win32
;
50 extern const struct ao_driver audio_out_dsound
;
51 extern const struct ao_driver audio_out_kai
;
52 extern const struct ao_driver audio_out_dart
;
53 extern const struct ao_driver audio_out_ivtv
;
54 extern const struct ao_driver audio_out_v4l2
;
55 extern const struct ao_driver audio_out_mpegpes
;
56 extern const struct ao_driver audio_out_pcm
;
57 extern const struct ao_driver audio_out_pss
;
59 static const struct ao_driver
* const audio_out_drivers
[] = {
64 #ifdef CONFIG_WIN32WAVEOUT
73 #ifdef CONFIG_COREAUDIO
82 #ifdef CONFIG_OSS_AUDIO
85 #ifdef CONFIG_SGI_AUDIO
88 #ifdef CONFIG_SUN_AUDIO
114 #ifdef CONFIG_V4L2_DECODER
118 // should not be auto-selected:
126 void list_audio_out(void)
129 mp_tmsg(MSGT_AO
, MSGL_INFO
, "Available audio output drivers:\n");
130 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_OUTPUTS\n");
131 while (audio_out_drivers
[i
]) {
132 const ao_info_t
*info
= audio_out_drivers
[i
++]->info
;
133 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "\t%s\t%s\n", info
->short_name
,
136 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\n");
139 struct ao
*ao_create(struct MPOpts
*opts
, struct input_ctx
*input
)
141 struct ao
*r
= talloc(NULL
, struct ao
);
142 *r
= (struct ao
){.outburst
= OUTBURST
, .buffersize
= -1,
143 .opts
= opts
, .input_ctx
= input
};
147 void ao_init(struct ao
*ao
, char **ao_list
)
149 /* Caller adding child blocks is not supported as we may call
150 * talloc_free_children() to clean up after failed open attempts.
152 assert(talloc_total_blocks(ao
) == 1);
153 struct ao backup
= *ao
;
158 // first try the preferred drivers, with their optional subdevice param:
160 char *ao_name
= *ao_list
;
162 goto try_defaults
; // empty entry means try defaults
164 char *params
= strchr(ao_name
, ':');
166 ao_len
= params
- ao_name
;
169 ao_len
= strlen(ao_name
);
171 mp_tmsg(MSGT_AO
, MSGL_V
,
172 "Trying preferred audio driver '%.*s', options '%s'\n",
173 ao_len
, ao_name
, params
? params
: "[none]");
175 const struct ao_driver
*audio_out
= NULL
;
176 for (int i
= 0; audio_out_drivers
[i
]; i
++) {
177 audio_out
= audio_out_drivers
[i
];
178 if (!strncmp(audio_out
->info
->short_name
, ao_name
, ao_len
))
183 // name matches, try it
184 ao
->driver
= audio_out
;
185 if (audio_out
->init(ao
, params
) >= 0) {
186 ao
->driver
= audio_out
;
187 ao
->initialized
= true;
190 mp_tmsg(MSGT_AO
, MSGL_WARN
,
191 "Failed to initialize audio driver '%s'\n", ao_name
);
192 talloc_free_children(ao
);
195 mp_tmsg(MSGT_AO
, MSGL_WARN
, "No such audio driver '%.*s'\n",
202 mp_tmsg(MSGT_AO
, MSGL_V
, "Trying every known audio driver...\n");
204 // now try the rest...
205 for (int i
= 0; audio_out_drivers
[i
]; i
++) {
206 const struct ao_driver
*audio_out
= audio_out_drivers
[i
];
207 ao
->driver
= audio_out
;
208 if (audio_out
->init(ao
, NULL
) >= 0) {
209 ao
->initialized
= true;
210 ao
->driver
= audio_out
;
213 talloc_free_children(ao
);
219 void ao_uninit(struct ao
*ao
, bool cut_audio
)
221 assert(ao
->buffer
.len
>= ao
->buffer_playable_size
);
222 ao
->buffer
.len
= ao
->buffer_playable_size
;
224 ao
->driver
->uninit(ao
, cut_audio
);
225 if (!cut_audio
&& ao
->buffer
.len
)
226 mp_msg(MSGT_AO
, MSGL_WARN
, "Audio output truncated at end.\n");
230 int ao_play(struct ao
*ao
, void *data
, int len
, int flags
)
232 return ao
->driver
->play(ao
, data
, len
, flags
);
235 int ao_control(struct ao
*ao
, int cmd
, void *arg
)
237 if (ao
->driver
->control
)
238 return ao
->driver
->control(ao
, cmd
, arg
);
239 return CONTROL_UNKNOWN
;
242 double ao_get_delay(struct ao
*ao
)
244 if (!ao
->driver
->get_delay
) {
248 return ao
->driver
->get_delay(ao
);
251 int ao_get_space(struct ao
*ao
)
253 return ao
->driver
->get_space(ao
);
256 void ao_reset(struct ao
*ao
)
259 ao
->buffer_playable_size
= 0;
260 if (ao
->driver
->reset
)
261 ao
->driver
->reset(ao
);
264 void ao_pause(struct ao
*ao
)
266 if (ao
->driver
->pause
)
267 ao
->driver
->pause(ao
);
270 void ao_resume(struct ao
*ao
)
272 if (ao
->driver
->resume
)
273 ao
->driver
->resume(ao
);
278 int old_ao_init(struct ao
*ao
, char *params
)
282 ao_subdevice
= params
? talloc_strdup(ao
, params
) : NULL
;
283 if (ao
->driver
->old_functions
->init(ao
->samplerate
, ao
->channels
,
284 ao
->format
, 0) == 0) {
291 void old_ao_uninit(struct ao
*ao
, bool cut_audio
)
293 ao
->driver
->old_functions
->uninit(cut_audio
);
297 int old_ao_play(struct ao
*ao
, void *data
, int len
, int flags
)
299 return ao
->driver
->old_functions
->play(data
, len
, flags
);
302 int old_ao_control(struct ao
*ao
, int cmd
, void *arg
)
304 return ao
->driver
->old_functions
->control(cmd
, arg
);
307 float old_ao_get_delay(struct ao
*ao
)
309 return ao
->driver
->old_functions
->get_delay();
312 int old_ao_get_space(struct ao
*ao
)
314 return ao
->driver
->old_functions
->get_space();
317 void old_ao_reset(struct ao
*ao
)
319 ao
->driver
->old_functions
->reset();
322 void old_ao_pause(struct ao
*ao
)
324 ao
->driver
->old_functions
->pause();
327 void old_ao_resume(struct ao
*ao
)
329 ao
->driver
->old_functions
->resume();