This didn't really work since the last time the channel map fallback code was touched. In some cases, quite bad results were selected.
Unified · Split
| @@ -234,29 +234,45 @@ bool mp_chmap_sel_fallback(const struct mp_chmap_sel *s, struct mp_chmap *map) · 233 unmodified lines | ||
| 234 | 234 | return true; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | − struct mp_chmap best = {0}; | |
| 237 | + struct mp_chmap best_of_best = {0}; | |
| 238 | + | |
| 239 | + for (int i = -1; i < (int)MP_ARRAY_SIZE(speaker_replacements); i++) { | |
| 240 | + struct mp_chmap best = {0}; | |
| 241 | + struct mp_chmap t = *map; | |
| 242 | + | |
| 243 | + if (i >= 0) { | |
| 244 | + struct mp_chmap *r = (struct mp_chmap *)speaker_replacements[i]; | |
| 245 | + if (!replace_speakers(&t, r)) | |
| 246 | + continue; | |
| 247 | + } | |
| 248 | + | |
| 249 | + for (int n = 0; n < s->num_chmaps; n++) { | |
| 250 | + struct mp_chmap e = s->chmaps[n]; | |
| 251 | + | |
| 252 | + if (mp_chmap_is_unknown(&e)) | |
| 253 | + continue; | |
| 238 | 254 | |
| 239 | − for (int n = 0; n < s->num_chmaps; n++) { | |
| 240 | − struct mp_chmap e = s->chmaps[n]; | |
| 241 | − | |
| 242 | − if (mp_chmap_is_unknown(&e)) | |
| 243 | − continue; | |
| 244 | − | |
| 245 | − // in case we didn't match any fallback retry after replacing speakers | |
| 246 | − for (int i = -1; i < (int)MP_ARRAY_SIZE(speaker_replacements); i++) { | |
| 247 | − struct mp_chmap t = *map; | |
| 248 | − if (i >= 0) { | |
| 249 | − struct mp_chmap *r = (struct mp_chmap *)speaker_replacements[i]; | |
| 250 | − if (!replace_speakers(&t, r)) | |
| 251 | − continue; | |
| 252 | − } | |
| 253 | 255 | if (mp_chmap_is_better(&t, &best, &e)) |
| 254 | 256 | best = e; |
| 255 | 257 | } |
| 258 | + | |
| 259 | + if (best.num) { | |
| 260 | + if (best_of_best.num) { | |
| 261 | + // If best (without replacements) is not worse, but is actually | |
| 262 | + // better with replacements applied, pick it. | |
| 263 | + int bbest_lost = mp_chmap_diffn(map, &best_of_best); | |
| 264 | + int best_lost = mp_chmap_diffn(map, &best); | |
| 265 | + int repl_lost = mp_chmap_diffn(&t, &best); | |
| 266 | + if (best_lost <= bbest_lost && repl_lost < bbest_lost) | |
| 267 | + best_of_best = best; | |
| 268 | + } else { | |
| 269 | + best_of_best = best; | |
| 270 | + } | |
| 271 | + } | |
| 256 | 272 | } |
| 257 | 273 | |
| 258 | − if (best.num) { | |
| 259 | − *map = best; | |
| 274 | + if (best_of_best.num) { | |
| 275 | + *map = best_of_best; | |
| 260 | 276 | return true; |
| 261 | 277 | } |
| 262 | 278 | |
| @@ -87,6 +87,20 @@ static void test_mp_chmap_sel_fallback_reject_unknown(void **state) { · 86 unmodified lines | ||
| 87 | 87 | assert_string_equal(mp_chmap_to_str(&b), "5.1"); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | +static void test_mp_chmap_sel_fallback_more_replacements(void **state) { | |
| 91 | + 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)")); | |
| 94 | + test_sel("quad", "7.1(wide-side)", LAYOUTS("7.1(wide-side)", "stereo")); | |
| 95 | + test_sel("quad", "7.1(wide-side)", LAYOUTS("stereo", "7.1(wide-side)")); | |
| 96 | + test_sel("quad", "fl-fr-fc-bl-br", | |
| 97 | + LAYOUTS("fl-fr-fc-bl-br", "fl-fr-sl-sr")); | |
| 98 | + test_sel("quad", "fl-fr-bl-br-na-na-na-na", | |
| 99 | + LAYOUTS("fl-fr-bl-br-na-na-na-na", "quad(side)", "stereo")); | |
| 100 | + test_sel("quad", "fl-fr-bl-br-na-na-na-na", | |
| 101 | + LAYOUTS("stereo", "quad(side)", "fl-fr-bl-br-na-na-na-na")); | |
| 102 | +} | |
| 103 | + | |
| 90 | 104 | int main(void) { |
| 91 | 105 | const UnitTest tests[] = { |
| 92 | 106 | unit_test(test_mp_chmap_sel_fallback_upmix), |
| @@ -101,6 +115,7 @@ int main(void) { · 8 unmodified lines | ||
| 101 | 115 | unit_test(test_mp_chmap_sel_fallback_no_downmix), |
| 102 | 116 | unit_test(test_mp_chmap_sel_fallback_minimal_downmix), |
| 103 | 117 | unit_test(test_mp_chmap_sel_fallback_reject_unknown), |
| 118 | + unit_test(test_mp_chmap_sel_fallback_more_replacements), | |
| 104 | 119 | }; |
| 105 | 120 | return run_tests(tests); |
| 106 | 121 | } |