summaryrefslogtreecommitdiffstats
path: root/audio/chmap.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-10-26 15:52:21 +0100
committerwm4 <wm4@nowhere>2015-10-26 15:52:21 +0100
commit76d1b430b0a8c846676dfd36852844134bafaff0 (patch)
treedb4eff9a0847c2dbafab20a4188b61d530f45713 /audio/chmap.c
parentec27d573f492f30c1111678273d56f922330fdcd (diff)
downloadmpv-76d1b430b0a8c846676dfd36852844134bafaff0.tar.bz2
mpv-76d1b430b0a8c846676dfd36852844134bafaff0.tar.xz
audio: improve mp_chmap_to_lavc_unchecked() unknown chmap behavior
Change it so that it will always return a bitmask with the correct number of channels set if an unknown channel map is passed. This didn't work for channel counts larger than 8, as there are not any standard channel layouts defined with more than 8 channels (both in mpv and FFmpeg). Instead, it returned 0. This will help when raising the maximum allowed channel count in mpv. Some code in af_lavrresample relies on it, more or less. One change is that unknown channel maps won't result in lavc standard channel layouts anymore, just a set of random speakers. This should be fine, as the caller of mp_chmap_to_lavc_unchecked() should handle these cases. For mp_chmap_reorder_to_lavc() this is not so clear anymore, but should also be ok. For normal channel maps, simply dropping NA channels is still the correct and wanted behavior. Currently, the mpv maximum channel count is 8. This commit is preparation for raising this limit.
Diffstat (limited to 'audio/chmap.c')
-rw-r--r--audio/chmap.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/audio/chmap.c b/audio/chmap.c
index 82f748b1cd..fb98be52df 100644
--- a/audio/chmap.c
+++ b/audio/chmap.c
@@ -298,12 +298,18 @@ void mp_chmap_remove_useless_channels(struct mp_chmap *map,
// Speakers not representable by ffmpeg/libav are dropped.
// Warning: this ignores the order of the channels, and will return a channel
// mask even if the order is different from libavcodec's.
+// Also, "unknown" channel maps are translated to non-sense channel
+// maps with the same number of channels.
uint64_t mp_chmap_to_lavc_unchecked(const struct mp_chmap *src)
{
- // lavc has no concept for unknown layouts yet, so pick a default
struct mp_chmap t = *src;
+ if (t.num > 64)
+ return 0;
+ // lavc has no concept for unknown layouts yet, so pick something that does
+ // the job of signaling the number of channels, even if it makes no sense
+ // as a proper layout.
if (mp_chmap_is_unknown(&t))
- mp_chmap_from_channels(&t, t.num);
+ return t.num == 64 ? (uint64_t)-1 : (1ULL << t.num) - 1;
uint64_t mask = 0;
for (int n = 0; n < t.num; n++) {
if (t.speaker[n] < 64) // ignore MP_SPEAKER_ID_NA etc.
@@ -359,6 +365,8 @@ bool mp_chmap_is_lavc(const struct mp_chmap *src)
return true;
}
+// Warning: for "unknown" channel maps, this returns something that may not
+// make sense. Invalid channel maps are not changed.
void mp_chmap_reorder_to_lavc(struct mp_chmap *map)
{
if (!mp_chmap_is_valid(map))