mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 01:22:30 +00:00
audio: add command/function to reload audio output
Anticipated use: simple solution for dealing with audio APIs which request configuration changes via events.
This commit is contained in:
parent
ac35e3b308
commit
d5b081152a
@ -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
|
||||
----------------------
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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 } },
|
||||
|
||||
|
@ -80,6 +80,7 @@ enum mp_command_type {
|
||||
|
||||
/// Audio Filter commands
|
||||
MP_CMD_AF,
|
||||
MP_CMD_AO_RELOAD,
|
||||
|
||||
/// Video filter commands
|
||||
MP_CMD_VF,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user