summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-25 19:10:24 +0200
committerwm4 <wm4@nowhere>2015-06-25 19:10:24 +0200
commit5a3cdb8f1e8b14daf11d44ef729a2484982b7305 (patch)
tree57369f90adb2e163dffc86b2649e7ba1d0f08077
parentfd1194de3c4b14126269f2db918c0f8bcf2bf34a (diff)
downloadmpv-5a3cdb8f1e8b14daf11d44ef729a2484982b7305.tar.bz2
mpv-5a3cdb8f1e8b14daf11d44ef729a2484982b7305.tar.xz
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.)
-rw-r--r--DOCS/interface-changes.rst1
-rw-r--r--DOCS/man/input.rst6
-rw-r--r--audio/audio.c8
-rw-r--r--audio/chmap.c19
-rw-r--r--audio/chmap.h3
-rw-r--r--audio/out/ao.c10
-rw-r--r--player/command.c1
7 files changed, 38 insertions, 10 deletions
diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst
index d0b4dfc72d..bf8fd991c6 100644
--- a/DOCS/interface-changes.rst
+++ b/DOCS/interface-changes.rst
@@ -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
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index 739268cb16..0ed259f59b 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -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
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;
}
diff --git a/player/command.c b/player/command.c
index 6bc2047250..852f232446 100644
--- a/player/command.c
+++ b/player/command.c
@@ -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}
};