2009-01-26 16:06:44 +01:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2001-06-03 01:25:43 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-10-22 18:24:26 +02:00
|
|
|
#include <string.h>
|
2011-04-09 02:03:22 +02:00
|
|
|
#include <assert.h>
|
2001-06-03 01:25:43 +02:00
|
|
|
|
2011-05-04 13:55:15 +02:00
|
|
|
#include "talloc.h"
|
|
|
|
|
2004-12-07 03:24:15 +01:00
|
|
|
#include "config.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "ao.h"
|
2013-06-16 18:47:02 +02:00
|
|
|
#include "audio/format.h"
|
2001-06-05 20:40:44 +02:00
|
|
|
|
2013-07-21 21:33:17 +02:00
|
|
|
#include "core/options.h"
|
|
|
|
#include "core/m_config.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/mp_msg.h"
|
2002-09-30 00:57:54 +02:00
|
|
|
|
2001-06-03 01:25:43 +02:00
|
|
|
// there are some globals:
|
2011-05-04 13:55:15 +02:00
|
|
|
struct ao *global_ao;
|
2001-06-22 00:34:58 +02:00
|
|
|
char *ao_subdevice = NULL;
|
2001-06-03 01:25:43 +02:00
|
|
|
|
2011-05-04 13:55:15 +02:00
|
|
|
extern const struct ao_driver audio_out_oss;
|
|
|
|
extern const struct ao_driver audio_out_coreaudio;
|
2011-06-24 15:56:43 +02:00
|
|
|
extern const struct ao_driver audio_out_rsound;
|
2011-05-04 13:55:15 +02:00
|
|
|
extern const struct ao_driver audio_out_pulse;
|
|
|
|
extern const struct ao_driver audio_out_jack;
|
|
|
|
extern const struct ao_driver audio_out_openal;
|
|
|
|
extern const struct ao_driver audio_out_null;
|
|
|
|
extern const struct ao_driver audio_out_alsa;
|
|
|
|
extern const struct ao_driver audio_out_dsound;
|
2013-06-13 15:15:39 +02:00
|
|
|
extern const struct ao_driver audio_out_wasapi0;
|
2011-05-04 13:55:15 +02:00
|
|
|
extern const struct ao_driver audio_out_pcm;
|
|
|
|
extern const struct ao_driver audio_out_pss;
|
2012-09-14 17:51:26 +02:00
|
|
|
extern const struct ao_driver audio_out_lavc;
|
2012-04-27 11:26:04 +02:00
|
|
|
extern const struct ao_driver audio_out_portaudio;
|
2012-12-28 08:07:14 +01:00
|
|
|
extern const struct ao_driver audio_out_sdl;
|
2011-05-04 13:55:15 +02:00
|
|
|
|
|
|
|
static const struct ao_driver * const audio_out_drivers[] = {
|
2002-10-06 03:08:04 +02:00
|
|
|
// native:
|
2008-08-06 09:42:26 +02:00
|
|
|
#ifdef CONFIG_COREAUDIO
|
2011-05-04 00:15:58 +02:00
|
|
|
&audio_out_coreaudio,
|
2005-10-12 01:07:53 +02:00
|
|
|
#endif
|
2012-01-05 15:02:03 +01:00
|
|
|
#ifdef CONFIG_PULSE
|
|
|
|
&audio_out_pulse,
|
2001-08-28 12:54:31 +02:00
|
|
|
#endif
|
2008-08-07 01:19:29 +02:00
|
|
|
#ifdef CONFIG_ALSA
|
2011-05-04 00:15:58 +02:00
|
|
|
&audio_out_alsa,
|
2002-05-28 03:52:40 +02:00
|
|
|
#endif
|
2012-01-05 15:02:03 +01:00
|
|
|
#ifdef CONFIG_OSS_AUDIO
|
|
|
|
&audio_out_oss,
|
|
|
|
#endif
|
2012-10-05 15:17:16 +02:00
|
|
|
#ifdef CONFIG_DSOUND
|
|
|
|
&audio_out_dsound,
|
2013-02-06 22:23:58 +01:00
|
|
|
#endif
|
2013-06-13 15:15:39 +02:00
|
|
|
#ifdef CONFIG_WASAPI0
|
|
|
|
&audio_out_wasapi0,
|
|
|
|
#endif
|
2013-02-06 22:23:58 +01:00
|
|
|
#ifdef CONFIG_PORTAUDIO
|
|
|
|
&audio_out_portaudio,
|
2001-06-05 12:37:50 +02:00
|
|
|
#endif
|
2011-05-04 00:15:58 +02:00
|
|
|
// wrappers:
|
2008-07-30 14:01:30 +02:00
|
|
|
#ifdef CONFIG_JACK
|
2011-05-04 00:15:58 +02:00
|
|
|
&audio_out_jack,
|
2004-06-25 20:11:15 +02:00
|
|
|
#endif
|
2008-07-30 14:01:30 +02:00
|
|
|
#ifdef CONFIG_OPENAL
|
2011-05-04 00:15:58 +02:00
|
|
|
&audio_out_openal,
|
2012-12-28 08:07:14 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SDL
|
|
|
|
&audio_out_sdl,
|
2006-02-16 23:35:04 +01:00
|
|
|
#endif
|
2011-05-04 00:15:58 +02:00
|
|
|
&audio_out_null,
|
|
|
|
// should not be auto-selected:
|
|
|
|
&audio_out_pcm,
|
2012-10-05 15:17:16 +02:00
|
|
|
#ifdef CONFIG_ENCODING
|
|
|
|
&audio_out_lavc,
|
|
|
|
#endif
|
2011-06-24 15:56:43 +02:00
|
|
|
#ifdef CONFIG_RSOUND
|
|
|
|
&audio_out_rsound,
|
|
|
|
#endif
|
2011-05-04 00:15:58 +02:00
|
|
|
NULL
|
2001-06-03 01:25:43 +02:00
|
|
|
};
|
2001-11-24 06:21:22 +01:00
|
|
|
|
2013-07-21 21:33:17 +02:00
|
|
|
static bool get_desc(struct m_obj_desc *dst, int index)
|
2011-05-04 00:15:58 +02:00
|
|
|
{
|
2013-07-21 21:33:17 +02:00
|
|
|
if (index >= MP_ARRAY_SIZE(audio_out_drivers) - 1)
|
|
|
|
return false;
|
|
|
|
const struct ao_driver *ao = audio_out_drivers[index];
|
|
|
|
*dst = (struct m_obj_desc) {
|
|
|
|
.name = ao->info->short_name,
|
|
|
|
.description = ao->info->name,
|
|
|
|
.priv_size = ao->priv_size,
|
|
|
|
.priv_defaults = ao->priv_defaults,
|
|
|
|
.options = ao->options,
|
2013-07-21 22:03:53 +02:00
|
|
|
.hidden = ao->encode,
|
2013-07-21 21:33:17 +02:00
|
|
|
.p = ao,
|
|
|
|
};
|
|
|
|
return true;
|
2002-09-30 00:57:54 +02:00
|
|
|
}
|
2001-11-24 06:21:22 +01:00
|
|
|
|
2013-07-21 21:33:17 +02:00
|
|
|
// For the ao option
|
|
|
|
const struct m_obj_list ao_obj_list = {
|
|
|
|
.get_desc = get_desc,
|
|
|
|
.description = "audio outputs",
|
|
|
|
.allow_unknown_entries = true,
|
|
|
|
.allow_trailer = true,
|
|
|
|
};
|
2011-04-09 02:03:22 +02:00
|
|
|
|
2013-07-21 21:33:17 +02:00
|
|
|
static struct ao *ao_create(bool probing, struct MPOpts *opts,
|
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx,
|
|
|
|
int samplerate, int format, struct mp_chmap channels,
|
|
|
|
char *name, char **args)
|
2013-02-06 22:54:03 +01:00
|
|
|
{
|
2013-07-21 21:33:17 +02:00
|
|
|
struct m_obj_desc desc;
|
|
|
|
if (!m_obj_list_find(&desc, &ao_obj_list, bstr0(name))) {
|
|
|
|
mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "Audio output %s not found!\n", name);
|
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
struct ao *ao = talloc_ptrtype(NULL, ao);
|
|
|
|
*ao = (struct ao) {
|
|
|
|
.driver = desc.p,
|
|
|
|
.probing = probing,
|
|
|
|
.opts = opts,
|
|
|
|
.encode_lavc_ctx = encode_lavc_ctx,
|
|
|
|
.input_ctx = input_ctx,
|
|
|
|
.samplerate = samplerate,
|
|
|
|
.channels = channels,
|
|
|
|
.format = format,
|
|
|
|
};
|
2013-02-06 22:54:03 +01:00
|
|
|
if (ao->driver->encode != !!ao->encode_lavc_ctx)
|
2013-07-21 21:33:17 +02:00
|
|
|
goto error;
|
|
|
|
struct m_config *config = m_config_from_obj_desc(ao, &desc);
|
|
|
|
if (m_config_initialize_obj(config, &desc, &ao->priv, &args) < 0)
|
|
|
|
goto error;
|
|
|
|
if (ao->driver->init(ao, (char *)args) < 0)
|
|
|
|
goto error;
|
2013-06-16 18:47:02 +02:00
|
|
|
ao->bps = ao->channels.num * ao->samplerate * af_fmt2bits(ao->format) / 8;
|
2013-07-21 21:33:17 +02:00
|
|
|
return ao;
|
|
|
|
error:
|
|
|
|
talloc_free(ao);
|
|
|
|
return NULL;
|
2013-02-06 22:54:03 +01:00
|
|
|
}
|
|
|
|
|
2013-07-21 21:33:17 +02:00
|
|
|
struct ao *ao_init_best(struct MPOpts *opts,
|
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx,
|
|
|
|
int samplerate, int format, struct mp_chmap channels)
|
2011-04-09 02:03:22 +02:00
|
|
|
{
|
2013-07-21 21:33:17 +02:00
|
|
|
struct m_obj_settings *ao_list = opts->audio_driver_list;
|
|
|
|
if (ao_list && ao_list[0].name) {
|
|
|
|
for (int n = 0; ao_list[n].name; n++) {
|
|
|
|
if (strlen(ao_list[n].name) == 0)
|
|
|
|
goto autoprobe;
|
|
|
|
mp_tmsg(MSGT_AO, MSGL_V, "Trying preferred audio driver '%s'\n",
|
|
|
|
ao_list[n].name);
|
|
|
|
struct ao *ao = ao_create(false, opts, input_ctx, encode_lavc_ctx,
|
|
|
|
samplerate, format, channels,
|
|
|
|
ao_list[n].name, ao_list[n].attribs);
|
|
|
|
if (ao)
|
|
|
|
return ao;
|
|
|
|
mp_tmsg(MSGT_AO, MSGL_WARN, "Failed to initialize audio driver '%s'\n",
|
|
|
|
ao_list[n].name);
|
2004-10-13 18:22:59 +02:00
|
|
|
}
|
2013-07-21 21:33:17 +02:00
|
|
|
return NULL;
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
2013-07-21 21:33:17 +02:00
|
|
|
autoprobe:
|
2002-09-30 00:57:54 +02:00
|
|
|
// now try the rest...
|
2011-04-09 02:03:22 +02:00
|
|
|
for (int i = 0; audio_out_drivers[i]; i++) {
|
2013-07-21 21:33:17 +02:00
|
|
|
struct ao *ao = ao_create(true, opts, input_ctx, encode_lavc_ctx,
|
|
|
|
samplerate, format, channels,
|
|
|
|
(char *)audio_out_drivers[i]->info->short_name, NULL);
|
|
|
|
if (ao)
|
|
|
|
return ao;
|
2002-09-30 00:57:54 +02:00
|
|
|
}
|
2013-07-21 21:33:17 +02:00
|
|
|
return NULL;
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
2011-05-04 13:55:15 +02:00
|
|
|
void ao_uninit(struct ao *ao, bool cut_audio)
|
2011-04-09 02:03:22 +02:00
|
|
|
{
|
2011-07-02 08:22:32 +02:00
|
|
|
assert(ao->buffer.len >= ao->buffer_playable_size);
|
|
|
|
ao->buffer.len = ao->buffer_playable_size;
|
2013-07-21 21:33:17 +02:00
|
|
|
ao->driver->uninit(ao, cut_audio);
|
2011-07-02 08:22:32 +02:00
|
|
|
if (!cut_audio && ao->buffer.len)
|
|
|
|
mp_msg(MSGT_AO, MSGL_WARN, "Audio output truncated at end.\n");
|
2011-05-04 13:55:15 +02:00
|
|
|
talloc_free(ao);
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ao_play(struct ao *ao, void *data, int len, int flags)
|
|
|
|
{
|
2011-05-04 13:55:15 +02:00
|
|
|
return ao->driver->play(ao, data, len, flags);
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
2012-04-07 15:26:56 +02:00
|
|
|
int ao_control(struct ao *ao, enum aocontrol cmd, void *arg)
|
2011-04-09 02:03:22 +02:00
|
|
|
{
|
2011-05-04 13:55:15 +02:00
|
|
|
if (ao->driver->control)
|
|
|
|
return ao->driver->control(ao, cmd, arg);
|
|
|
|
return CONTROL_UNKNOWN;
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double ao_get_delay(struct ao *ao)
|
|
|
|
{
|
2011-05-05 20:34:17 +02:00
|
|
|
if (!ao->driver->get_delay) {
|
|
|
|
assert(ao->untimed);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-04 13:55:15 +02:00
|
|
|
return ao->driver->get_delay(ao);
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ao_get_space(struct ao *ao)
|
|
|
|
{
|
2011-05-04 13:55:15 +02:00
|
|
|
return ao->driver->get_space(ao);
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ao_reset(struct ao *ao)
|
|
|
|
{
|
2011-07-02 08:22:32 +02:00
|
|
|
ao->buffer.len = 0;
|
|
|
|
ao->buffer_playable_size = 0;
|
2011-05-05 20:34:17 +02:00
|
|
|
if (ao->driver->reset)
|
|
|
|
ao->driver->reset(ao);
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ao_pause(struct ao *ao)
|
|
|
|
{
|
2011-05-05 20:34:17 +02:00
|
|
|
if (ao->driver->pause)
|
|
|
|
ao->driver->pause(ao);
|
2011-04-09 02:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ao_resume(struct ao *ao)
|
|
|
|
{
|
2011-05-05 20:34:17 +02:00
|
|
|
if (ao->driver->resume)
|
|
|
|
ao->driver->resume(ao);
|
2011-05-04 13:55:15 +02:00
|
|
|
}
|
|
|
|
|
2013-05-09 15:12:16 +02:00
|
|
|
bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s,
|
|
|
|
struct mp_chmap *map)
|
|
|
|
{
|
|
|
|
return mp_chmap_sel_adjust(s, map);
|
|
|
|
}
|
2011-05-04 13:55:15 +02:00
|
|
|
|
2013-05-09 15:12:16 +02:00
|
|
|
bool ao_chmap_sel_get_def(struct ao *ao, const struct mp_chmap_sel *s,
|
|
|
|
struct mp_chmap *map, int num)
|
|
|
|
{
|
|
|
|
return mp_chmap_sel_get_def(s, map, num);
|
|
|
|
}
|