From 1a7ab74fcca036a540364bedaef769fe2d43214b Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Tue, 11 Aug 2026 12:59:50 +1200 Subject: [PATCH 1/2] wasapi: Mix output when channel counts differ --- src/cubeb_wasapi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp index bb66c6264..f4c0f35ed 100644 --- a/src/cubeb_wasapi.cpp +++ b/src/cubeb_wasapi.cpp @@ -2838,7 +2838,8 @@ setup_wasapi_stream(cubeb_stream * stm) // Create output mixer. if (has_output(stm) && - stm->output_mix_params.layout != stm->output_stream_params.layout) { + (stm->output_mix_params.layout != stm->output_stream_params.layout || + stm->output_mix_params.channels != stm->output_stream_params.channels)) { if (stm->output_mix_params.layout == CUBEB_LAYOUT_UNDEFINED) { LOG("Output stream using undefined layout! Any mixing may be " "unpredictable!\n"); From 2bbb6741066287c83634b8dee62665c1c060d363 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Tue, 11 Aug 2026 13:07:41 +1200 Subject: [PATCH 2/2] cubeb: Reject inconsistent channel layouts --- src/cubeb.c | 11 +++++++++-- test/test_sanity.cpp | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/cubeb.c b/src/cubeb.c index 4fdead389..c47d4b804 100644 --- a/src/cubeb.c +++ b/src/cubeb.c @@ -7,6 +7,7 @@ #undef NDEBUG #include "cubeb/cubeb.h" #include "cubeb-internal.h" +#include "cubeb_mixer.h" #include #include #include @@ -97,7 +98,10 @@ validate_stream_params(cubeb_stream_params * input_stream_params, if (output_stream_params->rate < 1000 || output_stream_params->rate > 768000 || output_stream_params->channels < 1 || - output_stream_params->channels > UINT8_MAX) { + output_stream_params->channels > UINT8_MAX || + (output_stream_params->layout != CUBEB_LAYOUT_UNDEFINED && + cubeb_channel_layout_nb_channels(output_stream_params->layout) != + output_stream_params->channels)) { return CUBEB_ERROR_INVALID_FORMAT; } } @@ -105,7 +109,10 @@ validate_stream_params(cubeb_stream_params * input_stream_params, if (input_stream_params->rate < 1000 || input_stream_params->rate > 768000 || input_stream_params->channels < 1 || - input_stream_params->channels > UINT8_MAX) { + input_stream_params->channels > UINT8_MAX || + (input_stream_params->layout != CUBEB_LAYOUT_UNDEFINED && + cubeb_channel_layout_nb_channels(input_stream_params->layout) != + input_stream_params->channels)) { return CUBEB_ERROR_INVALID_FORMAT; } } diff --git a/test/test_sanity.cpp b/test/test_sanity.cpp index 17d3c542b..35ee1a958 100644 --- a/test/test_sanity.cpp +++ b/test/test_sanity.cpp @@ -279,6 +279,29 @@ TEST(cubeb, configure_stream_undefined_layout) cubeb_destroy(ctx); } +TEST(cubeb, reject_inconsistent_channel_layout) +{ + cubeb * ctx; + cubeb_stream * stream; + cubeb_stream_params params = {}; + + int r = common_init(&ctx, "test_sanity"); + ASSERT_EQ(r, CUBEB_OK); + ASSERT_NE(ctx, nullptr); + + params.format = CUBEB_SAMPLE_FLOAT32NE; + params.rate = STREAM_RATE; + params.channels = UINT8_MAX; + params.layout = CUBEB_LAYOUT_STEREO; + + r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, + STREAM_LATENCY, test_data_callback, test_state_callback, + &dummy); + EXPECT_EQ(r, CUBEB_ERROR_INVALID_FORMAT); + + cubeb_destroy(ctx); +} + static void test_init_start_stop_destroy_multiple_streams(int early, int delay_ms) {