diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/audio.c | 8 | ||||
-rw-r--r-- | audio/chmap.c | 19 | ||||
-rw-r--r-- | audio/chmap.h | 3 | ||||
-rw-r--r-- | audio/out/ao.c | 10 |
4 files changed, 30 insertions, 10 deletions
diff --git a/audio/audio.c b/audio/audio.c index a61e8c458c..c4ffc233a1 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -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; } diff --git a/audio/chmap.c b/audio/chmap.c index 3bc2d2b15a..82f748b1cd 100644 --- a/audio/chmap.c +++ b/audio/chmap.c @@ -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"); diff --git a/audio/chmap.h b/audio/chmap.h index ba1072547b..b27ec3bda8 100644 --- a/audio/chmap.h +++ b/audio/chmap.h @@ -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; diff --git a/audio/out/ao.c b/audio/out/ao.c index 4b9b2f9bec..c1333ab584 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -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; } |