Skip to content

Commit dac5b59

Browse files
author
wm4
committed
chmap_sel: prefer inexact equivalents over perfect upmix
Given 5.1(side), this lets it pick 5.1 from [5.1, 7.1]. Which was probably the original intention of this replacement stuff. Until now, the opposite was done in some cases. Keep the old heuristic if the replacement is not perfect. This would mean that a subset of the channel layout is an inexact equivalent, but not all of it. (My conclusion is that audio output APIs should be designed to simply take any channel layout, like the PulseAudio API does.)
1 parent cb8b0cc commit dac5b59

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

audio/chmap_sel.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,25 @@ static bool mp_chmap_is_better(struct mp_chmap *req, struct mp_chmap *old,
274274
if (new_lost_r != old_lost_r)
275275
return new_lost_r < old_lost_r;
276276

277+
struct mp_chmap old_p = *old, new_p = *new;
278+
mp_chmap_remove_na(&old_p);
279+
mp_chmap_remove_na(&new_p);
280+
281+
// If the situation is equal with replaced speakers, but the replacement is
282+
// perfect for only one of them, let the better one win. This prefers
283+
// inexact equivalents over exact supersets.
284+
bool perfect_r_new = !new_lost_r && new_p.num <= old_p.num;
285+
bool perfect_r_old = !old_lost_r && old_p.num <= new_p.num;
286+
if (perfect_r_new != perfect_r_old)
287+
return perfect_r_new;
288+
277289
int old_lost = mp_chmap_diffn(req, old);
278290
int new_lost = mp_chmap_diffn(req, new);
279-
280-
// If the situation is equal with replaced speakers, but one of them loses
281-
// less if no replacements are performed, pick the better one, even if it
282-
// means an upmix. This prefers exact supersets over inexact equivalents.
291+
// If the situation is equal with replaced speakers, pick the better one,
292+
// even if it means an upmix.
283293
if (new_lost != old_lost)
284294
return new_lost < old_lost;
285295

286-
struct mp_chmap old_p = *old, new_p = *new;
287-
mp_chmap_remove_na(&old_p);
288-
mp_chmap_remove_na(&new_p);
289-
290296
// Some kind of upmix. If it's perfect, prefer the smaller one. Even if not,
291297
// both have equal loss, so also prefer the smaller one.
292298
// Drop padding channels (NA) for the sake of this check, as the number of

test/chmap_sel.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ static void test_mp_chmap_sel_fallback_use_replacements(void **state) {
5252
test_sel("5.1", "7.1(rear)", LAYOUTS("7.1(rear)"));
5353
}
5454

55+
static void test_mp_chmap_sel_fallback_inexact_equivalent(void **state) {
56+
test_sel("5.1(side)", "5.1", LAYOUTS("5.1", "7.1"));
57+
}
58+
5559
static void test_mp_chmap_sel_fallback_works_on_alsa_chmaps(void **state) {
5660
test_sel("5.1", "7.1(alsa)", LAYOUTS("7.1(alsa)"));
5761
}
@@ -89,11 +93,11 @@ static void test_mp_chmap_sel_fallback_reject_unknown(void **state) {
8993

9094
static void test_mp_chmap_sel_fallback_more_replacements(void **state) {
9195
test_sel("quad", "quad(side)", LAYOUTS("quad(side)", "stereo"));
92-
test_sel("quad", "7.0", LAYOUTS("quad(side)", "7.0"));
93-
test_sel("quad", "7.0", LAYOUTS("7.0", "quad(side)"));
96+
test_sel("quad", "quad(side)", LAYOUTS("quad(side)", "7.0"));
97+
test_sel("quad", "quad(side)", LAYOUTS("7.0", "quad(side)"));
9498
test_sel("quad", "7.1(wide-side)", LAYOUTS("7.1(wide-side)", "stereo"));
9599
test_sel("quad", "7.1(wide-side)", LAYOUTS("stereo", "7.1(wide-side)"));
96-
test_sel("quad", "fl-fr-fc-bl-br",
100+
test_sel("quad", "fl-fr-sl-sr",
97101
LAYOUTS("fl-fr-fc-bl-br", "fl-fr-sl-sr"));
98102
test_sel("quad", "fl-fr-bl-br-na-na-na-na",
99103
LAYOUTS("fl-fr-bl-br-na-na-na-na", "quad(side)", "stereo"));
@@ -118,6 +122,7 @@ int main(void) {
118122
cmocka_unit_test(test_mp_chmap_sel_fallback_prefer_compatible),
119123
cmocka_unit_test(test_mp_chmap_sel_fallback_prefer_closest_upmix),
120124
cmocka_unit_test(test_mp_chmap_sel_fallback_use_replacements),
125+
cmocka_unit_test(test_mp_chmap_sel_fallback_inexact_equivalent),
121126
cmocka_unit_test(test_mp_chmap_sel_fallback_works_on_alsa_chmaps),
122127
cmocka_unit_test(test_mp_chmap_sel_fallback_mono_to_stereo),
123128
cmocka_unit_test(test_mp_chmap_sel_fallback_stereo_to_stereo),

0 commit comments

Comments
 (0)