From d5b081152aecb947215f7b8aa091ca2031c94edc Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 27 Oct 2014 11:52:42 +0100 Subject: audio: add command/function to reload audio output Anticipated use: simple solution for dealing with audio APIs which request configuration changes via events. --- DOCS/man/input.rst | 2 +- audio/out/ao.c | 8 ++++++++ audio/out/internal.h | 2 ++ input/cmd_list.c | 1 + input/cmd_list.h | 1 + player/command.c | 16 ++++++++++++++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 56b9cd9d61..dca64657fe 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -544,7 +544,7 @@ Input Commands that are Possibly Subject to Change Undocumented commands: ``tv_last_channel`` (TV/DVB only), ``get_property`` (?), -``vo_cmdline`` (experimental). +``vo_cmdline`` (experimental), ``ao_reload`` (experimental/internal). Input Command Prefixes ---------------------- diff --git a/audio/out/ao.c b/audio/out/ao.c index ef228780f8..b94e459091 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -29,6 +29,7 @@ #include "audio/format.h" #include "audio/audio.h" +#include "input/input.h" #include "options/options.h" #include "options/m_config.h" #include "common/msg.h" @@ -406,6 +407,13 @@ bool ao_chmap_sel_get_def(struct ao *ao, const struct mp_chmap_sel *s, return mp_chmap_sel_get_def(s, map, num); } +// Request that the player core destroys and recreates the AO. +void ao_request_reload(struct ao *ao) +{ + const char *cmd[] = {"ao_reload", NULL}; + mp_input_run_cmd(ao->input_ctx, cmd); +} + // --- The following functions just return immutable information. void ao_get_format(struct ao *ao, struct mp_audio *format) diff --git a/audio/out/internal.h b/audio/out/internal.h index cebc265f04..fd45a4a581 100644 --- a/audio/out/internal.h +++ b/audio/out/internal.h @@ -183,6 +183,8 @@ bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s, bool ao_chmap_sel_get_def(struct ao *ao, const struct mp_chmap_sel *s, struct mp_chmap *map, int num); +void ao_request_reload(struct ao *ao); + // Add a deep copy of e to the list. // Call from ao_driver->list_devs callback only. void ao_device_list_add(struct ao_device_list *list, struct ao *ao, diff --git a/input/cmd_list.c b/input/cmd_list.c index fe014c4983..e281c84f9e 100644 --- a/input/cmd_list.c +++ b/input/cmd_list.c @@ -156,6 +156,7 @@ const struct mp_cmd_def mp_cmds[] = { { MP_CMD_DISCNAV, "discnav", { ARG_STRING } }, { MP_CMD_AF, "af", { ARG_STRING, ARG_STRING } }, + { MP_CMD_AO_RELOAD, "ao_reload", }, { MP_CMD_VF, "vf", { ARG_STRING, ARG_STRING } }, diff --git a/input/cmd_list.h b/input/cmd_list.h index 7d395cb329..c99ac58be9 100644 --- a/input/cmd_list.h +++ b/input/cmd_list.h @@ -80,6 +80,7 @@ enum mp_command_type { /// Audio Filter commands MP_CMD_AF, + MP_CMD_AO_RELOAD, /// Video filter commands MP_CMD_VF, diff --git a/player/command.c b/player/command.c index 5cdd57110c..a4ef70082c 100644 --- a/player/command.c +++ b/player/command.c @@ -1454,6 +1454,18 @@ static int get_device_entry(int item, int action, void *arg, void *ctx) return m_property_read_sub(props, action, arg); } +static void reload_audio_output(struct MPContext *mpctx) +{ + if (!mpctx->ao) + return; + ao_reset(mpctx->ao); + uninit_audio_out(mpctx); + // This normally recreates the AO, although there are situations when AO + // creation is delayed; for example if there are no audio packets around, + // and the audio format is yet unknown. + reinit_audio_chain(mpctx); +} + static int mp_property_audio_devices(void *ctx, struct m_property *prop, int action, void *arg) { @@ -4233,6 +4245,10 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd) } break; + case MP_CMD_AO_RELOAD: + reload_audio_output(mpctx); + break; + case MP_CMD_AF: return edit_filters_osd(mpctx, STREAM_AUDIO, cmd->args[0].v.s, cmd->args[1].v.s, msg_osd); -- cgit v1.2.3