diff options
author | wm4 <wm4@nowhere> | 2013-05-09 15:12:16 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-05-12 21:24:57 +0200 |
commit | ab8f28a672fbd8d21a98c265976068e80be082a7 (patch) | |
tree | c3dd738bf7711c23dba5e2ed45c234f34024523b /audio/chmap.c | |
parent | 34a139d49533386c104edbc1b0ed226201989bb9 (diff) | |
download | mpv-ab8f28a672fbd8d21a98c265976068e80be082a7.tar.bz2 mpv-ab8f28a672fbd8d21a98c265976068e80be082a7.tar.xz |
audio: add channel map selection function
The point is selecting a minimal fallback. The AOs will call this
through the AO API, so it will be possible to add options affecting
the general channel layout selection.
It provides the following mechanism to AOs:
- forcing the correct channel order
- downmixing to stereo if no layout is available
- allow 5.1 <-> 5.1(side) fallback
- handling "unknown" channel layouts
This is quite weak and lots of code/complexity for little gain. All AOs
already made sure the channel order was correct, and the fallback is of
little value, and could perhaps be done in the frontend instead, like
stereo downmixing with --channels=2 is handled. But I'm not really sure
how this stuff should _really_ work, and the new code will hopefully
provides enough flexibility to make radical changes to channel layout
negotiation easier.
Diffstat (limited to 'audio/chmap.c')
-rw-r--r-- | audio/chmap.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/audio/chmap.c b/audio/chmap.c index 61df408e02..fcdb95edb3 100644 --- a/audio/chmap.c +++ b/audio/chmap.c @@ -100,6 +100,17 @@ static const struct mp_chmap default_layouts[MP_NUM_CHANNELS + 1] = { MP_CHMAP8(FL, FR, FC, LFE, BL, BR, SL, SR), // 7.1 }; +// The channel order was lavc/waveex, but differs from lavc for 5, 6 and 8 +// channels. 3 and 7 channels were likely undefined (no ALSA support). +static const char *mplayer_layouts[MP_NUM_CHANNELS + 1] = { + [1] = "mono", + [2] = "stereo", + [4] = "4.0", + [5] = "5.0(alsa)", + [6] = "5.1(alsa)", + [8] = "7.1(alsa)", +}; + // Returns true if speakers are mapped uniquely, and there's at least 1 channel. bool mp_chmap_is_valid(const struct mp_chmap *src) { @@ -192,6 +203,19 @@ void mp_chmap_from_channels(struct mp_chmap *dst, int num_channels) } } +// Try to do what mplayer/mplayer2/mpv did before channel layouts were +// introduced, i.e. get the old default channel order. +void mp_chmap_from_channels_alsa(struct mp_chmap *dst, int num_channels) +{ + if (num_channels < 0 || num_channels > MP_NUM_CHANNELS) { + *dst = (struct mp_chmap) {0}; + } else { + mp_chmap_from_str(dst, bstr0(mplayer_layouts[num_channels])); + if (!dst->num) + mp_chmap_from_channels(dst, num_channels); + } +} + // Set *dst to an unknown layout for the given numbers of channels. // If the number of channels is invalid, an invalid map is set, and // mp_chmap_is_valid(dst) will return false. @@ -314,22 +338,6 @@ void mp_chmap_reorder_to_lavc(struct mp_chmap *map) mp_chmap_from_lavc(map, mask); } -// Try to do what mplayer/mplayer2/mpv did before channel layouts were -// introduced, i.e. get the old default channel order. -void mp_chmap_reorder_to_alsa(struct mp_chmap *map) -{ - // The channel order was lavc/waveex, but differs from lavc for 5, 6 and 8 - // channels. 3 and 7 channels were likely undefined (no ALSA support). - mp_chmap_from_channels(map, map->num); - if (map->num == 5) { - mp_chmap_from_str(map, bstr0("5.0(alsa)")); - } else if (map->num == 6) { - mp_chmap_from_str(map, bstr0("5.1(alsa)")); - } else if (map->num == 8) { - mp_chmap_from_str(map, bstr0("7.1(alsa)")); - } -} - // Get reordering array for from->to reordering. from->to must have the same set // of speakers (i.e. same number and speaker IDs, just different order). Then, // for each speaker n, dst[n] will be set such that: |