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_rsound
;
38 extern const struct ao_driver audio_out_pulse
;
39 extern const struct ao_driver audio_out_jack
;
40 extern const struct ao_driver audio_out_openal
;
41 extern const struct ao_driver audio_out_null
;
42 extern const struct ao_driver audio_out_alsa
;
43 extern const struct ao_driver audio_out_sdl
;
44 extern const struct ao_driver audio_out_dsound
;
45 extern const struct ao_driver audio_out_v4l2
;
46 extern const struct ao_driver audio_out_pcm
;
47 extern const struct ao_driver audio_out_pss
;
48 extern const struct ao_driver audio_out_portaudio
;
50 static const struct ao_driver
* const audio_out_drivers
[] = {
55 #ifdef CONFIG_COREAUDIO
64 #ifdef CONFIG_OSS_AUDIO
67 #ifdef CONFIG_PORTAUDIO
80 #ifdef CONFIG_V4L2_DECODER
84 // should not be auto-selected:
92 void list_audio_out(void)
95 mp_tmsg(MSGT_AO
, MSGL_INFO
, "Available audio output drivers:\n");
96 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_OUTPUTS\n");
97 while (audio_out_drivers
[i
]) {
98 const ao_info_t
*info
= audio_out_drivers
[i
++]->info
;
99 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "\t%s\t%s\n", info
->short_name
,
102 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\n");
105 struct ao
*ao_create(struct MPOpts
*opts
, struct input_ctx
*input
)
107 struct ao
*r
= talloc(NULL
, struct ao
);
108 *r
= (struct ao
){.outburst
= 512, .buffersize
= -1,
109 .opts
= opts
, .input_ctx
= input
};
113 void ao_init(struct ao
*ao
, char **ao_list
)
115 /* Caller adding child blocks is not supported as we may call
116 * talloc_free_children() to clean up after failed open attempts.
118 assert(talloc_total_blocks(ao
) == 1);
119 struct ao backup
= *ao
;
124 // first try the preferred drivers, with their optional subdevice param:
126 char *ao_name
= *ao_list
;
128 goto try_defaults
; // empty entry means try defaults
130 char *params
= strchr(ao_name
, ':');
132 ao_len
= params
- ao_name
;
135 ao_len
= strlen(ao_name
);
137 mp_tmsg(MSGT_AO
, MSGL_V
,
138 "Trying preferred audio driver '%.*s', options '%s'\n",
139 ao_len
, ao_name
, params
? params
: "[none]");
141 const struct ao_driver
*audio_out
= NULL
;
142 for (int i
= 0; audio_out_drivers
[i
]; i
++) {
143 audio_out
= audio_out_drivers
[i
];
144 if (!strncmp(audio_out
->info
->short_name
, ao_name
, ao_len
))
149 // name matches, try it
150 ao
->driver
= audio_out
;
151 if (audio_out
->init(ao
, params
) >= 0) {
152 ao
->driver
= audio_out
;
153 ao
->initialized
= true;
156 mp_tmsg(MSGT_AO
, MSGL_WARN
,
157 "Failed to initialize audio driver '%s'\n", ao_name
);
158 talloc_free_children(ao
);
161 mp_tmsg(MSGT_AO
, MSGL_WARN
, "No such audio driver '%.*s'\n",
168 mp_tmsg(MSGT_AO
, MSGL_V
, "Trying every known audio driver...\n");
170 // now try the rest...
171 for (int i
= 0; audio_out_drivers
[i
]; i
++) {
172 const struct ao_driver
*audio_out
= audio_out_drivers
[i
];
173 ao
->driver
= audio_out
;
174 if (audio_out
->init(ao
, NULL
) >= 0) {
175 ao
->initialized
= true;
176 ao
->driver
= audio_out
;
179 talloc_free_children(ao
);
185 void ao_uninit(struct ao
*ao
, bool cut_audio
)
187 assert(ao
->buffer
.len
>= ao
->buffer_playable_size
);
188 ao
->buffer
.len
= ao
->buffer_playable_size
;
190 ao
->driver
->uninit(ao
, cut_audio
);
191 if (!cut_audio
&& ao
->buffer
.len
)
192 mp_msg(MSGT_AO
, MSGL_WARN
, "Audio output truncated at end.\n");
196 int ao_play(struct ao
*ao
, void *data
, int len
, int flags
)
198 return ao
->driver
->play(ao
, data
, len
, flags
);
201 int ao_control(struct ao
*ao
, enum aocontrol cmd
, void *arg
)
203 if (ao
->driver
->control
)
204 return ao
->driver
->control(ao
, cmd
, arg
);
205 return CONTROL_UNKNOWN
;
208 double ao_get_delay(struct ao
*ao
)
210 if (!ao
->driver
->get_delay
) {
214 return ao
->driver
->get_delay(ao
);
217 int ao_get_space(struct ao
*ao
)
219 return ao
->driver
->get_space(ao
);
222 void ao_reset(struct ao
*ao
)
225 ao
->buffer_playable_size
= 0;
226 if (ao
->driver
->reset
)
227 ao
->driver
->reset(ao
);
230 void ao_pause(struct ao
*ao
)
232 if (ao
->driver
->pause
)
233 ao
->driver
->pause(ao
);
236 void ao_resume(struct ao
*ao
)
238 if (ao
->driver
->resume
)
239 ao
->driver
->resume(ao
);
244 int old_ao_init(struct ao
*ao
, char *params
)
248 ao_subdevice
= params
? talloc_strdup(ao
, params
) : NULL
;
249 if (ao
->driver
->old_functions
->init(ao
->samplerate
, ao
->channels
,
250 ao
->format
, 0) == 0) {
257 void old_ao_uninit(struct ao
*ao
, bool cut_audio
)
259 ao
->driver
->old_functions
->uninit(cut_audio
);
263 int old_ao_play(struct ao
*ao
, void *data
, int len
, int flags
)
265 return ao
->driver
->old_functions
->play(data
, len
, flags
);
268 int old_ao_control(struct ao
*ao
, enum aocontrol cmd
, void *arg
)
270 return ao
->driver
->old_functions
->control(cmd
, arg
);
273 float old_ao_get_delay(struct ao
*ao
)
275 return ao
->driver
->old_functions
->get_delay();
278 int old_ao_get_space(struct ao
*ao
)
280 return ao
->driver
->old_functions
->get_space();
283 void old_ao_reset(struct ao
*ao
)
285 ao
->driver
->old_functions
->reset();
288 void old_ao_pause(struct ao
*ao
)
290 ao
->driver
->old_functions
->pause();
293 void old_ao_resume(struct ao
*ao
)
295 ao
->driver
->old_functions
->resume();