mirror of
https://github.com/mpv-player/mpv
synced 2025-02-20 23:07:02 +00:00
audio: output human-readable channel layouts too
This gets you the "logical" channel layout, instead of the exact thing we're sending to the AO. (Tired of the cryptic shit ALSA gives me.)
This commit is contained in:
parent
fd1194de3c
commit
5a3cdb8f1e
@ -20,6 +20,7 @@ Interface changes
|
||||
::
|
||||
|
||||
--- mpv 0.10.0 will be released ---
|
||||
- add audio-params/channel-count and ``audio-params-out/channel-count props.
|
||||
- add af volume replaygain-fallback suboption
|
||||
- add video-params/stereo-in property
|
||||
- add "keypress", "keydown", and "keyup" commands
|
||||
|
@ -1181,6 +1181,11 @@ Property list
|
||||
The channel layout as a string. This is similar to what the
|
||||
``--audio-channels`` accepts.
|
||||
|
||||
``audio-params/hr-channels``
|
||||
As ``channels``, but instead of the possibly cryptic actual layout
|
||||
sent to the audio device, return a hopefully more human readable form.
|
||||
(Usually only ``audio-out-params/hr-channels`` makes sense.)
|
||||
|
||||
``audio-params/channel-count``
|
||||
Number of audio channels. This is redundant to the ``channels`` field
|
||||
described above.
|
||||
@ -1197,6 +1202,7 @@ Property list
|
||||
"samplerate" MPV_FORMAT_INT64
|
||||
"channels" MPV_FORMAT_STRING
|
||||
"channel-count" MPV_FORMAT_INT64
|
||||
"hr-channels" MPV_FORMAT_STRING
|
||||
|
||||
``audio-out-params``
|
||||
Same as ``audio-params``, but the format of the data written to the audio
|
||||
|
@ -93,9 +93,13 @@ bool mp_audio_config_valid(const struct mp_audio *mpa)
|
||||
|
||||
char *mp_audio_config_to_str_buf(char *buf, size_t buf_sz, struct mp_audio *mpa)
|
||||
{
|
||||
char ch[128];
|
||||
mp_chmap_to_str_buf(ch, sizeof(ch), &mpa->channels);
|
||||
char *hr_ch = mp_chmap_to_str_hr(&mpa->channels);
|
||||
if (strcmp(hr_ch, ch) != 0)
|
||||
mp_snprintf_cat(ch, sizeof(ch), " (%s)", hr_ch);
|
||||
snprintf(buf, buf_sz, "%dHz %s %dch %s", mpa->rate,
|
||||
mp_chmap_to_str(&mpa->channels), mpa->channels.num,
|
||||
af_fmt_to_str(mpa->format));
|
||||
ch, mpa->channels.num, af_fmt_to_str(mpa->format));
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -508,6 +508,25 @@ bool mp_chmap_from_str(struct mp_chmap *dst, bstr src)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Output a human readable "canonical" channel map string. Converting this from
|
||||
// a string back to a channel map can yield a different map, but the string
|
||||
// looks nicer. E.g. "fc-fl-fr-na" becomes "3.0".
|
||||
char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap *src)
|
||||
{
|
||||
struct mp_chmap map = *src;
|
||||
mp_chmap_remove_na(&map);
|
||||
for (int n = 0; std_layout_names[n][0]; n++) {
|
||||
struct mp_chmap s;
|
||||
if (mp_chmap_from_str(&s, bstr0(std_layout_names[n][0])) &&
|
||||
mp_chmap_equals_reordered(&s, &map))
|
||||
{
|
||||
map = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mp_chmap_to_str_buf(buf, buf_size, &map);
|
||||
}
|
||||
|
||||
void mp_chmap_print_help(struct mp_log *log)
|
||||
{
|
||||
mp_info(log, "Speakers:\n");
|
||||
|
@ -128,6 +128,9 @@ int mp_chmap_diffn(const struct mp_chmap *a, const struct mp_chmap *b);
|
||||
char *mp_chmap_to_str_buf(char *buf, size_t buf_size, const struct mp_chmap *src);
|
||||
#define mp_chmap_to_str(m) mp_chmap_to_str_buf((char[64]){0}, 64, (m))
|
||||
|
||||
char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap *src);
|
||||
#define mp_chmap_to_str_hr(m) mp_chmap_to_str_hr_buf((char[128]){0}, 128, (m))
|
||||
|
||||
bool mp_chmap_from_str(struct mp_chmap *dst, bstr src);
|
||||
|
||||
struct mp_log;
|
||||
|
@ -414,20 +414,14 @@ bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s,
|
||||
if (mp_msg_test(ao->log, MSGL_DEBUG)) {
|
||||
for (int i = 0; i < s->num_chmaps; i++) {
|
||||
struct mp_chmap c = s->chmaps[i];
|
||||
struct mp_chmap cr = c;
|
||||
mp_chmap_reorder_norm(&cr);
|
||||
mp_chmap_remove_na(&cr);
|
||||
MP_DBG(ao, "chmap_sel #%d: %s (%s)\n", i, mp_chmap_to_str(&c),
|
||||
mp_chmap_to_str(&cr));
|
||||
mp_chmap_to_str_hr(&c));
|
||||
}
|
||||
}
|
||||
bool r = mp_chmap_sel_adjust(s, map);
|
||||
if (r) {
|
||||
struct mp_chmap mapr = *map;
|
||||
mp_chmap_reorder_norm(&mapr);
|
||||
mp_chmap_remove_na(&mapr);
|
||||
MP_DBG(ao, "result: %s (%s)\n", mp_chmap_to_str(map),
|
||||
mp_chmap_to_str(&mapr));
|
||||
mp_chmap_to_str_hr(map));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
@ -1664,6 +1664,7 @@ static int property_audiofmt(struct mp_audio a, int action, void *arg)
|
||||
{"samplerate", SUB_PROP_INT(a.rate)},
|
||||
{"channel-count", SUB_PROP_INT(a.channels.num)},
|
||||
{"channels", SUB_PROP_STR(mp_chmap_to_str(&a.channels))},
|
||||
{"hr-channels", SUB_PROP_STR(mp_chmap_to_str_hr(&a.channels))},
|
||||
{"format", SUB_PROP_STR(af_fmt_to_str(a.format))},
|
||||
{0}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user