mirror of
https://github.com/mpv-player/mpv
synced 2025-03-08 07:08:12 +00:00
chmap_sel: add channel replacement for sl/sr <-> sdl/sdr
This can be use useful for the 7.1 rear layout. In particular it looks like OS X likes to use sdl/sdr as opposed to sl/sr.
This commit is contained in:
parent
26b00ffe8a
commit
e7d1c12131
@ -18,21 +18,21 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "common/common.h"
|
||||||
#include "chmap_sel.h"
|
#include "chmap_sel.h"
|
||||||
|
|
||||||
// 5.1 and 5.1(side) are practically the same. It doesn't make much sense to
|
static struct mp_chmap speaker_replacements[][2] = {
|
||||||
// reject either of them.
|
// 5.1 <-> 5.1 (side)
|
||||||
static const int replaceable_speakers[][2] = {
|
{ MP_CHMAP2(SL, SR), MP_CHMAP2(BL, BR) },
|
||||||
{MP_SPEAKER_ID_SL, MP_SPEAKER_ID_BL},
|
// 7.1 <-> 7.1 (rear ext)
|
||||||
{MP_SPEAKER_ID_SR, MP_SPEAKER_ID_BR},
|
{ MP_CHMAP2(SL, SR), MP_CHMAP2(SDL, SDR) },
|
||||||
{-1},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// list[] contains a list of speaker pairs, with each pair indicating how
|
// Try to replace speakers from the left of the list with the ones on the
|
||||||
// a speaker can be swapped for another speaker. Try to replace speakers from
|
// right, or the other way around.
|
||||||
// the left of the list with the ones on the right, or the other way around.
|
static bool replace_speakers(struct mp_chmap *map, struct mp_chmap list[2])
|
||||||
static bool replace_speakers(struct mp_chmap *map, const int list[][2])
|
|
||||||
{
|
{
|
||||||
|
assert(list[0].num == list[1].num);
|
||||||
if (!mp_chmap_is_valid(map))
|
if (!mp_chmap_is_valid(map))
|
||||||
return false;
|
return false;
|
||||||
for (int dir = 0; dir < 2; dir++) {
|
for (int dir = 0; dir < 2; dir++) {
|
||||||
@ -41,9 +41,9 @@ static bool replace_speakers(struct mp_chmap *map, const int list[][2])
|
|||||||
bool replaced = false;
|
bool replaced = false;
|
||||||
struct mp_chmap t = *map;
|
struct mp_chmap t = *map;
|
||||||
for (int n = 0; n < t.num; n++) {
|
for (int n = 0; n < t.num; n++) {
|
||||||
for (int i = 0; list[i][0] != -1; i++) {
|
for (int i = 0; i < list[0].num; i++) {
|
||||||
if (t.speaker[n] == list[i][from]) {
|
if (t.speaker[n] == list[from].speaker[i]) {
|
||||||
t.speaker[n] = list[i][to];
|
t.speaker[n] = list[to].speaker[i];
|
||||||
replaced = true;
|
replaced = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -168,9 +168,14 @@ bool mp_chmap_sel_adjust(const struct mp_chmap_sel *s, struct mp_chmap *map)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 5.1 <-> 5.1(side)
|
for (int i = 0; i < MP_ARRAY_SIZE(speaker_replacements); i++) {
|
||||||
if (replace_speakers(map, replaceable_speakers) && test_layout(s, map))
|
struct mp_chmap t = *map;
|
||||||
return true;
|
struct mp_chmap *r = speaker_replacements[i];
|
||||||
|
if (replace_speakers(&t, r) && test_layout(s, &t)) {
|
||||||
|
*map = t;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Fallback to mono/stereo as last resort
|
// Fallback to mono/stereo as last resort
|
||||||
if (map->num == 1) {
|
if (map->num == 1) {
|
||||||
*map = (struct mp_chmap) MP_CHMAP_INIT_MONO;
|
*map = (struct mp_chmap) MP_CHMAP_INIT_MONO;
|
||||||
|
Loading…
Reference in New Issue
Block a user