1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00

command: add property returning detected audio device

This can be useful to adjust some other audio related properties
at runtime depending on the audio device being used.
This commit is contained in:
Stefano Pigozzi 2015-02-02 23:01:11 +01:00
parent dd287a3276
commit a3be14683a
6 changed files with 26 additions and 1 deletions

View File

@ -1589,6 +1589,10 @@ Property list
``current-ao`` ``current-ao``
Current audio output driver (name as used with ``--ao``). Current audio output driver (name as used with ``--ao``).
``audio-out-detected-device``
Return the audio device selected by the AO driver (only implemented for
some drivers: currently only ``coreaudio``).
``mpv-version`` ``mpv-version``
Return the mpv version/copyright string. Depending on how the binary was Return the mpv version/copyright string. Depending on how the binary was
built, it might contain either a release version, or just a git hash. built, it might contain either a release version, or just a git hash.

View File

@ -440,6 +440,11 @@ bool ao_untimed(struct ao *ao)
return ao->untimed; return ao->untimed;
} }
const char *ao_get_detected_device(struct ao *ao)
{
return ao->detected_device;
}
struct ao_device_list *ao_get_device_list(struct mpv_global *global) struct ao_device_list *ao_get_device_list(struct mpv_global *global)
{ {
struct ao_device_list *list = talloc_zero(NULL, struct ao_device_list); struct ao_device_list *list = talloc_zero(NULL, struct ao_device_list);

View File

@ -79,6 +79,7 @@ void ao_uninit(struct ao *ao);
void ao_get_format(struct ao *ao, struct mp_audio *format); void ao_get_format(struct ao *ao, struct mp_audio *format);
const char *ao_get_name(struct ao *ao); const char *ao_get_name(struct ao *ao);
const char *ao_get_description(struct ao *ao); const char *ao_get_description(struct ao *ao);
const char *ao_get_detected_device(struct ao *ao);
bool ao_untimed(struct ao *ao); bool ao_untimed(struct ao *ao);
int ao_play(struct ao *ao, void **data, int samples, int flags); int ao_play(struct ao *ao, void **data, int samples, int flags);
int ao_control(struct ao *ao, enum aocontrol cmd, void *arg); int ao_control(struct ao *ao, enum aocontrol cmd, void *arg);

View File

@ -156,6 +156,8 @@ static int init(struct ao *ao)
OSStatus err = ca_select_device(ao, ao->device, &p->device); OSStatus err = ca_select_device(ao, ao->device, &p->device);
CHECK_CA_ERROR("failed to select device"); CHECK_CA_ERROR("failed to select device");
ao->detected_device = talloc_asprintf(ao, "%d", p->device);
if (!init_chmap(ao)) if (!init_chmap(ao))
goto coreaudio_error; goto coreaudio_error;

View File

@ -50,6 +50,9 @@ struct ao {
// default device should be used, this is set to NULL. // default device should be used, this is set to NULL.
char *device; char *device;
// Device actually chosen by the AO
char *detected_device;
// Application name to report to the audio API. // Application name to report to the audio API.
char *client_name; char *client_name;

View File

@ -1577,6 +1577,15 @@ static int mp_property_ao(void *ctx, struct m_property *p, int action, void *arg
mpctx->ao ? ao_get_name(mpctx->ao) : NULL); mpctx->ao ? ao_get_name(mpctx->ao) : NULL);
} }
static int mp_property_ao_detected_device(void *ctx,struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->ao)
return M_PROPERTY_UNAVAILABLE;
return m_property_strdup_ro(action, arg, ao_get_detected_device(mpctx->ao));
}
/// Audio delay (RW) /// Audio delay (RW)
static int mp_property_audio_delay(void *ctx, struct m_property *prop, static int mp_property_audio_delay(void *ctx, struct m_property *prop,
int action, void *arg) int action, void *arg)
@ -3375,6 +3384,7 @@ static const struct m_property mp_properties[] = {
{"audio-device", mp_property_audio_device}, {"audio-device", mp_property_audio_device},
{"audio-device-list", mp_property_audio_devices}, {"audio-device-list", mp_property_audio_devices},
{"current-ao", mp_property_ao}, {"current-ao", mp_property_ao},
{"audio-out-detected-device", mp_property_ao_detected_device},
// Video // Video
{"fullscreen", mp_property_fullscreen}, {"fullscreen", mp_property_fullscreen},
@ -3516,7 +3526,7 @@ static const char *const *const mp_event_property_change[] = {
"detected-hwdec"), "detected-hwdec"),
E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate", E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate",
"samplerate", "channels", "audio", "volume", "mute", "balance", "samplerate", "channels", "audio", "volume", "mute", "balance",
"volume-restore-data", "current-ao"), "volume-restore-data", "current-ao", "audio-out-detected-device"),
E(MPV_EVENT_SEEK, "seeking", "core-idle"), E(MPV_EVENT_SEEK, "seeking", "core-idle"),
E(MPV_EVENT_PLAYBACK_RESTART, "seeking", "core-idle"), E(MPV_EVENT_PLAYBACK_RESTART, "seeking", "core-idle"),
E(MPV_EVENT_METADATA_UPDATE, "metadata", "filtered-metadata"), E(MPV_EVENT_METADATA_UPDATE, "metadata", "filtered-metadata"),