2009-01-26 15:06:44 +00: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-02 23:25:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-10-22 16:24:26 +00:00
|
|
|
#include <string.h>
|
2011-04-09 00:03:22 +00:00
|
|
|
#include <assert.h>
|
2001-06-02 23:25:43 +00:00
|
|
|
|
2011-05-04 11:55:15 +00:00
|
|
|
#include "talloc.h"
|
|
|
|
|
2004-12-07 02:24:15 +00:00
|
|
|
#include "config.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "ao.h"
|
2014-03-07 14:24:32 +00:00
|
|
|
#include "internal.h"
|
2013-06-16 16:47:02 +00:00
|
|
|
#include "audio/format.h"
|
2014-03-07 14:24:32 +00:00
|
|
|
#include "audio/audio.h"
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
|
|
|
#include "options/m_config.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2014-03-08 23:04:37 +00:00
|
|
|
#include "common/common.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/global.h"
|
2002-09-29 22:57:54 +00:00
|
|
|
|
2011-05-04 11:55:15 +00:00
|
|
|
extern const struct ao_driver audio_out_oss;
|
|
|
|
extern const struct ao_driver audio_out_coreaudio;
|
2014-06-30 17:09:03 +00:00
|
|
|
extern const struct ao_driver audio_out_coreaudio_exclusive;
|
2011-06-24 13:56:43 +00:00
|
|
|
extern const struct ao_driver audio_out_rsound;
|
2013-09-28 16:01:12 +00:00
|
|
|
extern const struct ao_driver audio_out_sndio;
|
2011-05-04 11:55:15 +00: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-07-20 17:13:39 +00:00
|
|
|
extern const struct ao_driver audio_out_wasapi;
|
2011-05-04 11:55:15 +00:00
|
|
|
extern const struct ao_driver audio_out_pcm;
|
2012-09-14 15:51:26 +00:00
|
|
|
extern const struct ao_driver audio_out_lavc;
|
2012-04-27 09:26:04 +00:00
|
|
|
extern const struct ao_driver audio_out_portaudio;
|
2012-12-28 07:07:14 +00:00
|
|
|
extern const struct ao_driver audio_out_sdl;
|
2011-05-04 11:55:15 +00:00
|
|
|
|
|
|
|
static const struct ao_driver * const audio_out_drivers[] = {
|
2002-10-06 01:08:04 +00:00
|
|
|
// native:
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_COREAUDIO
|
2011-05-03 22:15:58 +00:00
|
|
|
&audio_out_coreaudio,
|
2005-10-11 23:07:53 +00:00
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_PULSE
|
2012-01-05 14:02:03 +00:00
|
|
|
&audio_out_pulse,
|
2001-08-28 10:54:31 +00:00
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_ALSA
|
2011-05-03 22:15:58 +00:00
|
|
|
&audio_out_alsa,
|
2002-05-28 01:52:40 +00:00
|
|
|
#endif
|
2014-06-01 17:00:44 +00:00
|
|
|
#if HAVE_DSOUND
|
|
|
|
&audio_out_dsound,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_WASAPI
|
2013-07-20 02:42:58 +00:00
|
|
|
&audio_out_wasapi,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_OSS_AUDIO
|
2012-01-05 14:02:03 +00:00
|
|
|
&audio_out_oss,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_PORTAUDIO
|
2013-02-06 21:23:58 +00:00
|
|
|
&audio_out_portaudio,
|
2001-06-05 10:37:50 +00:00
|
|
|
#endif
|
2011-05-03 22:15:58 +00:00
|
|
|
// wrappers:
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_JACK
|
2011-05-03 22:15:58 +00:00
|
|
|
&audio_out_jack,
|
2004-06-25 18:11:15 +00:00
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_OPENAL
|
2011-05-03 22:15:58 +00:00
|
|
|
&audio_out_openal,
|
2012-12-28 07:07:14 +00:00
|
|
|
#endif
|
2014-01-25 08:18:07 +00:00
|
|
|
#if HAVE_SDL1 || HAVE_SDL2
|
2012-12-28 07:07:14 +00:00
|
|
|
&audio_out_sdl,
|
2014-09-26 13:52:29 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SNDIO
|
|
|
|
&audio_out_sndio,
|
2006-02-16 22:35:04 +00:00
|
|
|
#endif
|
2011-05-03 22:15:58 +00:00
|
|
|
&audio_out_null,
|
|
|
|
// should not be auto-selected:
|
|
|
|
&audio_out_pcm,
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_ENCODING
|
2012-10-05 13:17:16 +00:00
|
|
|
&audio_out_lavc,
|
|
|
|
#endif
|
2014-06-30 17:09:03 +00:00
|
|
|
#if HAVE_COREAUDIO
|
|
|
|
&audio_out_coreaudio_exclusive,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_RSOUND
|
2011-06-24 13:56:43 +00:00
|
|
|
&audio_out_rsound,
|
|
|
|
#endif
|
2011-05-03 22:15:58 +00:00
|
|
|
NULL
|
2001-06-02 23:25:43 +00:00
|
|
|
};
|
2001-11-24 05:21:22 +00:00
|
|
|
|
2013-07-21 19:33:17 +00:00
|
|
|
static bool get_desc(struct m_obj_desc *dst, int index)
|
2011-05-03 22:15:58 +00:00
|
|
|
{
|
2013-07-21 19:33:17 +00: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) {
|
2013-10-23 17:07:27 +00:00
|
|
|
.name = ao->name,
|
|
|
|
.description = ao->description,
|
2013-07-21 19:33:17 +00:00
|
|
|
.priv_size = ao->priv_size,
|
|
|
|
.priv_defaults = ao->priv_defaults,
|
|
|
|
.options = ao->options,
|
2013-07-21 20:03:53 +00:00
|
|
|
.hidden = ao->encode,
|
2013-07-21 19:33:17 +00:00
|
|
|
.p = ao,
|
|
|
|
};
|
|
|
|
return true;
|
2002-09-29 22:57:54 +00:00
|
|
|
}
|
2001-11-24 05:21:22 +00:00
|
|
|
|
2013-07-21 19:33:17 +00: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 00:03:22 +00:00
|
|
|
|
2014-10-09 19:21:31 +00:00
|
|
|
// Return true if the ao with the given name matches the opt (--audio-device
|
|
|
|
// contents). If opt is empty, matching always succeeds. If out_device is not
|
|
|
|
// NULL, it will be set to the implied audio device (or NULL).
|
|
|
|
static bool match_ao_driver(const char *ao_name, char *opt, char **out_device)
|
|
|
|
{
|
|
|
|
bstr ao_nameb = bstr0(ao_name);
|
|
|
|
bstr optb = bstr0(opt);
|
|
|
|
|
|
|
|
char *dummy;
|
|
|
|
if (!out_device)
|
|
|
|
out_device = &dummy;
|
|
|
|
*out_device = NULL;
|
|
|
|
|
|
|
|
if (!optb.len || bstr_equals0(optb, "auto"))
|
|
|
|
return true;
|
|
|
|
if (!bstr_startswith(optb, ao_nameb))
|
|
|
|
return false;
|
|
|
|
if (optb.len > ao_nameb.len && optb.start[ao_nameb.len] != '/')
|
|
|
|
return false;
|
|
|
|
char *split = strchr(opt, '/');
|
|
|
|
*out_device = split ? split + 1 : NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-10 16:27:21 +00:00
|
|
|
static struct ao *ao_alloc(bool probing, struct mpv_global *global,
|
|
|
|
struct input_ctx *input_ctx, char *name, char **args)
|
2013-02-06 21:54:03 +00:00
|
|
|
{
|
2014-10-09 19:21:31 +00:00
|
|
|
struct MPOpts *opts = global->opts;
|
2013-08-01 15:41:32 +00:00
|
|
|
struct mp_log *log = mp_log_new(NULL, global->log, "ao");
|
2013-07-21 19:33:17 +00:00
|
|
|
struct m_obj_desc desc;
|
|
|
|
if (!m_obj_list_find(&desc, &ao_obj_list, bstr0(name))) {
|
2013-12-21 20:49:13 +00:00
|
|
|
mp_msg(log, MSGL_ERR, "Audio output %s not found!\n", name);
|
2013-08-01 15:41:32 +00:00
|
|
|
talloc_free(log);
|
2013-07-21 19:33:17 +00:00
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
struct ao *ao = talloc_ptrtype(NULL, ao);
|
2013-08-01 15:41:32 +00:00
|
|
|
talloc_steal(ao, log);
|
2013-07-21 19:33:17 +00:00
|
|
|
*ao = (struct ao) {
|
|
|
|
.driver = desc.p,
|
|
|
|
.probing = probing,
|
|
|
|
.input_ctx = input_ctx,
|
2013-08-01 15:41:32 +00:00
|
|
|
.log = mp_log_new(ao, log, name),
|
2014-10-09 19:21:31 +00:00
|
|
|
.def_buffer = opts->audio_buffer,
|
2013-07-21 19:33:17 +00:00
|
|
|
};
|
2013-12-21 18:45:42 +00:00
|
|
|
struct m_config *config = m_config_from_obj_desc(ao, ao->log, &desc);
|
2014-10-09 19:21:31 +00:00
|
|
|
if (m_config_apply_defaults(config, name, opts->ao_defs) < 0)
|
2013-11-30 23:12:10 +00:00
|
|
|
goto error;
|
2013-07-22 20:57:51 +00:00
|
|
|
if (m_config_set_obj_params(config, args) < 0)
|
2013-07-21 19:33:17 +00:00
|
|
|
goto error;
|
2013-07-22 20:57:51 +00:00
|
|
|
ao->priv = config->optstruct;
|
2014-10-10 16:27:21 +00:00
|
|
|
return ao;
|
|
|
|
error:
|
|
|
|
talloc_free(ao);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ao *ao_create(bool probing, struct mpv_global *global,
|
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx,
|
|
|
|
int samplerate, int format, struct mp_chmap channels,
|
|
|
|
char *name, char **args)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = global->opts;
|
|
|
|
struct ao *ao = ao_alloc(probing, global, input_ctx, name, args);
|
|
|
|
ao->samplerate = samplerate;
|
|
|
|
ao->channels = channels;
|
|
|
|
ao->format = format;
|
|
|
|
ao->encode_lavc_ctx = encode_lavc_ctx;
|
|
|
|
if (ao->driver->encode != !!ao->encode_lavc_ctx)
|
|
|
|
goto error;
|
2014-03-08 23:04:37 +00:00
|
|
|
|
2014-10-09 19:21:31 +00:00
|
|
|
match_ao_driver(ao->driver->name, opts->audio_device, &ao->device);
|
|
|
|
ao->device = talloc_strdup(ao, ao->device);
|
|
|
|
|
2013-11-09 22:18:09 +00:00
|
|
|
char *chmap = mp_chmap_to_str(&ao->channels);
|
|
|
|
MP_VERBOSE(ao, "requested format: %d Hz, %s channels, %s\n",
|
|
|
|
ao->samplerate, chmap, af_fmt_to_str(ao->format));
|
|
|
|
talloc_free(chmap);
|
2014-03-08 23:04:37 +00:00
|
|
|
|
|
|
|
ao->api = ao->driver->play ? &ao_api_push : &ao_api_pull;
|
|
|
|
ao->api_priv = talloc_zero_size(ao, ao->api->priv_size);
|
|
|
|
assert(!ao->api->priv_defaults && !ao->api->options);
|
|
|
|
|
2013-07-22 20:57:51 +00:00
|
|
|
if (ao->driver->init(ao) < 0)
|
2013-07-21 19:33:17 +00:00
|
|
|
goto error;
|
2014-03-08 23:04:37 +00:00
|
|
|
|
2014-05-27 06:21:18 +00:00
|
|
|
ao->sstride = af_fmt2bps(ao->format);
|
2014-03-08 23:04:37 +00:00
|
|
|
ao->num_planes = 1;
|
|
|
|
if (af_fmt_is_planar(ao->format)) {
|
|
|
|
ao->num_planes = ao->channels.num;
|
|
|
|
} else {
|
2013-11-10 22:24:21 +00:00
|
|
|
ao->sstride *= ao->channels.num;
|
2014-03-08 23:04:37 +00:00
|
|
|
}
|
2013-11-10 22:24:21 +00:00
|
|
|
ao->bps = ao->samplerate * ao->sstride;
|
2014-03-08 23:04:37 +00:00
|
|
|
|
2014-03-14 21:37:19 +00:00
|
|
|
if (!ao->device_buffer && ao->driver->get_space) {
|
2014-03-08 23:04:37 +00:00
|
|
|
ao->device_buffer = ao->driver->get_space(ao);
|
2014-03-14 21:37:19 +00:00
|
|
|
MP_VERBOSE(ao, "device buffer: %d samples.\n", ao->device_buffer);
|
|
|
|
}
|
2014-09-04 21:48:27 +00:00
|
|
|
ao->buffer = MPMAX(ao->device_buffer, ao->def_buffer * ao->samplerate);
|
2014-03-08 23:04:37 +00:00
|
|
|
MP_VERBOSE(ao, "using soft-buffer of %d samples.\n", ao->buffer);
|
|
|
|
|
|
|
|
if (ao->api->init(ao) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-07-21 19:33:17 +00:00
|
|
|
return ao;
|
|
|
|
error:
|
|
|
|
talloc_free(ao);
|
|
|
|
return NULL;
|
2013-02-06 21:54:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 15:41:32 +00:00
|
|
|
struct ao *ao_init_best(struct mpv_global *global,
|
2013-07-21 19:33:17 +00:00
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx,
|
|
|
|
int samplerate, int format, struct mp_chmap channels)
|
2011-04-09 00:03:22 +00:00
|
|
|
{
|
2014-10-09 19:21:31 +00:00
|
|
|
struct MPOpts *opts = global->opts;
|
2013-12-21 17:43:03 +00:00
|
|
|
struct mp_log *log = mp_log_new(NULL, global->log, "ao");
|
|
|
|
struct ao *ao = NULL;
|
2014-10-09 19:21:31 +00:00
|
|
|
struct m_obj_settings *ao_list = opts->audio_driver_list;
|
2013-07-21 19:33:17 +00:00
|
|
|
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;
|
2013-12-21 17:43:03 +00:00
|
|
|
mp_verbose(log, "Trying preferred audio driver '%s'\n",
|
|
|
|
ao_list[n].name);
|
|
|
|
ao = ao_create(false, global, input_ctx, encode_lavc_ctx,
|
|
|
|
samplerate, format, channels,
|
|
|
|
ao_list[n].name, ao_list[n].attribs);
|
2013-07-21 19:33:17 +00:00
|
|
|
if (ao)
|
2013-12-21 17:43:03 +00:00
|
|
|
goto done;
|
|
|
|
mp_warn(log, "Failed to initialize audio driver '%s'\n",
|
2013-07-21 19:33:17 +00:00
|
|
|
ao_list[n].name);
|
2004-10-13 16:22:59 +00:00
|
|
|
}
|
2013-12-21 17:43:03 +00:00
|
|
|
goto done;
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
2014-10-09 19:21:31 +00:00
|
|
|
autoprobe: ;
|
2002-09-29 22:57:54 +00:00
|
|
|
// now try the rest...
|
2014-10-09 19:21:31 +00:00
|
|
|
bool matched_dev = false;
|
2011-04-09 00:03:22 +00:00
|
|
|
for (int i = 0; audio_out_drivers[i]; i++) {
|
2014-10-09 19:21:31 +00:00
|
|
|
char *name = (char *)audio_out_drivers[i]->name;
|
|
|
|
if (!match_ao_driver(name, opts->audio_device, NULL))
|
|
|
|
continue;
|
|
|
|
matched_dev = true;
|
2013-12-21 17:43:03 +00:00
|
|
|
ao = ao_create(true, global, input_ctx, encode_lavc_ctx,
|
2014-10-09 19:21:31 +00:00
|
|
|
samplerate, format, channels, name, NULL);
|
2013-07-21 19:33:17 +00:00
|
|
|
if (ao)
|
2013-12-21 17:43:03 +00:00
|
|
|
goto done;
|
2002-09-29 22:57:54 +00:00
|
|
|
}
|
2014-10-09 19:21:31 +00:00
|
|
|
if (!matched_dev)
|
|
|
|
mp_err(log, "--audio-device option refers to missing output driver.\n");
|
2013-12-21 17:43:03 +00:00
|
|
|
done:
|
|
|
|
talloc_free(log);
|
|
|
|
return ao;
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-08 23:49:39 +00:00
|
|
|
// Uninitialize and destroy the AO. Remaining audio must be dropped.
|
|
|
|
void ao_uninit(struct ao *ao)
|
2011-04-09 00:03:22 +00:00
|
|
|
{
|
2014-03-08 23:49:39 +00:00
|
|
|
ao->api->uninit(ao);
|
2011-05-04 11:55:15 +00:00
|
|
|
talloc_free(ao);
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 23:56:10 +00:00
|
|
|
// Queue the given audio data. Start playback if it hasn't started yet. Return
|
|
|
|
// the number of samples that was accepted (the core will try to queue the rest
|
|
|
|
// again later). Should never block.
|
|
|
|
// data: start pointer for each plane. If the audio data is packed, only
|
|
|
|
// data[0] is valid, otherwise there is a plane for each channel.
|
|
|
|
// samples: size of the audio data (see ao->sstride)
|
|
|
|
// flags: currently AOPLAY_FINAL_CHUNK can be set
|
2013-11-10 22:38:18 +00:00
|
|
|
int ao_play(struct ao *ao, void **data, int samples, int flags)
|
2011-04-09 00:03:22 +00:00
|
|
|
{
|
2014-03-08 23:04:37 +00:00
|
|
|
return ao->api->play(ao, data, samples, flags);
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 13:26:56 +00:00
|
|
|
int ao_control(struct ao *ao, enum aocontrol cmd, void *arg)
|
2011-04-09 00:03:22 +00:00
|
|
|
{
|
2014-09-06 00:30:57 +00:00
|
|
|
return ao->api->control ? ao->api->control(ao, cmd, arg) : CONTROL_UNKNOWN;
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 23:56:10 +00:00
|
|
|
// Return size of the buffered data in seconds. Can include the device latency.
|
|
|
|
// Basically, this returns how much data there is still to play, and how long
|
|
|
|
// it takes until the last sample in the buffer reaches the speakers. This is
|
|
|
|
// used for audio/video synchronization, so it's very important to implement
|
|
|
|
// this correctly.
|
2011-04-09 00:03:22 +00:00
|
|
|
double ao_get_delay(struct ao *ao)
|
|
|
|
{
|
2014-03-08 23:04:37 +00:00
|
|
|
return ao->api->get_delay(ao);
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 23:56:10 +00:00
|
|
|
// Return free size of the internal audio buffer. This controls how much audio
|
|
|
|
// the core should decode and try to queue with ao_play().
|
2011-04-09 00:03:22 +00:00
|
|
|
int ao_get_space(struct ao *ao)
|
|
|
|
{
|
2014-03-08 23:04:37 +00:00
|
|
|
return ao->api->get_space(ao);
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 23:56:10 +00:00
|
|
|
// Stop playback and empty buffers. Essentially go back to the state after
|
|
|
|
// ao->init().
|
2011-04-09 00:03:22 +00:00
|
|
|
void ao_reset(struct ao *ao)
|
|
|
|
{
|
2014-03-08 23:04:37 +00:00
|
|
|
if (ao->api->reset)
|
|
|
|
ao->api->reset(ao);
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 23:56:10 +00:00
|
|
|
// Pause playback. Keep the current buffer. ao_get_delay() must return the
|
|
|
|
// same value as before pausing.
|
2011-04-09 00:03:22 +00:00
|
|
|
void ao_pause(struct ao *ao)
|
|
|
|
{
|
2014-03-08 23:04:37 +00:00
|
|
|
if (ao->api->pause)
|
|
|
|
ao->api->pause(ao);
|
2011-04-09 00:03:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 23:56:10 +00:00
|
|
|
// Resume playback. Play the remaining buffer. If the driver doesn't support
|
|
|
|
// pausing, it has to work around this and e.g. use ao_play_silence() to fill
|
|
|
|
// the lost audio.
|
2011-04-09 00:03:22 +00:00
|
|
|
void ao_resume(struct ao *ao)
|
|
|
|
{
|
2014-03-08 23:04:37 +00:00
|
|
|
if (ao->api->resume)
|
|
|
|
ao->api->resume(ao);
|
2011-05-04 11:55:15 +00:00
|
|
|
}
|
|
|
|
|
2014-03-08 23:49:39 +00:00
|
|
|
// Block until the current audio buffer has played completely.
|
|
|
|
void ao_drain(struct ao *ao)
|
|
|
|
{
|
2014-07-13 18:06:33 +00:00
|
|
|
if (ao->api->drain)
|
2014-03-08 23:49:39 +00:00
|
|
|
ao->api->drain(ao);
|
2013-11-10 22:05:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 21:48:09 +00:00
|
|
|
bool ao_eof_reached(struct ao *ao)
|
|
|
|
{
|
2014-09-05 20:21:06 +00:00
|
|
|
return ao->api->get_eof ? ao->api->get_eof(ao) : true;
|
2014-04-17 21:48:09 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 13:12:16 +00: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 11:55:15 +00:00
|
|
|
|
2013-05-09 13:12:16 +00: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);
|
|
|
|
}
|
2014-03-07 14:24:32 +00:00
|
|
|
|
|
|
|
// --- The following functions just return immutable information.
|
|
|
|
|
|
|
|
void ao_get_format(struct ao *ao, struct mp_audio *format)
|
|
|
|
{
|
|
|
|
*format = (struct mp_audio){0};
|
|
|
|
mp_audio_set_format(format, ao->format);
|
|
|
|
mp_audio_set_channels(format, &ao->channels);
|
|
|
|
format->rate = ao->samplerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ao_get_name(struct ao *ao)
|
|
|
|
{
|
|
|
|
return ao->driver->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ao_get_description(struct ao *ao)
|
|
|
|
{
|
|
|
|
return ao->driver->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ao_untimed(struct ao *ao)
|
|
|
|
{
|
|
|
|
return ao->untimed;
|
|
|
|
}
|
2014-10-09 19:21:31 +00:00
|
|
|
|
2014-10-10 16:27:21 +00:00
|
|
|
struct ao_device_list *ao_get_device_list(struct mpv_global *global)
|
2014-10-09 19:21:31 +00:00
|
|
|
{
|
|
|
|
struct ao_device_list *list = talloc_zero(NULL, struct ao_device_list);
|
|
|
|
for (int n = 0; audio_out_drivers[n]; n++) {
|
|
|
|
const struct ao_driver *d = audio_out_drivers[n];
|
2014-10-10 16:27:21 +00:00
|
|
|
struct ao *ao = ao_alloc(true, global, NULL, (char *)d->name, NULL);
|
|
|
|
if (!ao)
|
|
|
|
continue;
|
2014-10-09 19:21:31 +00:00
|
|
|
int num = list->num_devices;
|
|
|
|
if (d->list_devs)
|
2014-10-10 16:27:21 +00:00
|
|
|
d->list_devs(ao, list);
|
2014-10-09 19:21:31 +00:00
|
|
|
// Add at least a default entry
|
|
|
|
if (list->num_devices == num)
|
2014-10-10 16:27:21 +00:00
|
|
|
ao_device_list_add(list, ao, &(struct ao_device_desc){"", ""});
|
|
|
|
talloc_free(ao);
|
2014-10-09 19:21:31 +00:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-10-10 16:27:21 +00:00
|
|
|
void ao_device_list_add(struct ao_device_list *list, struct ao *ao,
|
2014-10-09 19:21:31 +00:00
|
|
|
struct ao_device_desc *e)
|
|
|
|
{
|
|
|
|
struct ao_device_desc c = *e;
|
2014-10-10 16:27:21 +00:00
|
|
|
const char *dname = ao->driver->name;
|
|
|
|
c.name = c.name[0] ? talloc_asprintf(list, "%s/%s", dname, c.name)
|
|
|
|
: talloc_strdup(list, dname);
|
2014-10-09 19:21:31 +00:00
|
|
|
c.desc = talloc_strdup(list, c.desc);
|
|
|
|
MP_TARRAY_APPEND(list, list->devices, list->num_devices, c);
|
|
|
|
}
|
|
|
|
|
2014-10-10 16:27:21 +00:00
|
|
|
void ao_print_devices(struct mpv_global *global, struct mp_log *log)
|
2014-10-09 19:21:31 +00:00
|
|
|
{
|
2014-10-10 16:27:21 +00:00
|
|
|
struct ao_device_list *list = ao_get_device_list(global);
|
2014-10-09 19:21:31 +00:00
|
|
|
mp_info(log, "List of detected audio devices:\n");
|
|
|
|
for (int n = 0; n < list->num_devices; n++) {
|
|
|
|
struct ao_device_desc *desc = &list->devices[n];
|
|
|
|
mp_info(log, " %s (%s)\n", desc->name, desc->desc);
|
|
|
|
}
|
|
|
|
talloc_free(list);
|
|
|
|
}
|