Attempt to allow up to 31 channels of output, up from a limit of 8. Modify the mixdown setting so that "auto" only mixes downwards, e.g. 7.1 to 5.1, and never upwards, e.g. stereo to 5.1. Upmixing is not functional anyway, as the upmixing matrices are all such that the input channels are copied to their equivalent output channels and other output channels remain silent.

This commit is contained in:
Mike Brady
2026-05-07 14:06:00 +01:00
parent 281fb34d57
commit a50eed043e
3 changed files with 34 additions and 7 deletions
+25 -4
View File
@@ -656,24 +656,43 @@ int setup_software_resampler(rtsp_conn_info *conn, ssrc_t ssrc) {
// set the resampler's channel layout either automatically or use the
// setting that has been given
// We impose the rule that, if the mixdown setting is "auto",
// we will not upmix if the number of output channels available
// is greater than the number of channels needed.
// To do an upmix, you will have to specify the upmix target, e.g. "7.1"
// in the mixdown setting.
// NOTE: upmixing at present, by default, simply copies the input channels to their
// equivalents in the output channel set. All the other channels are
// left alone.
#if LIBAVUTIL_VERSION_MAJOR >= 57
{
AVChannelLayout input_channel_layout;
av_channel_layout_from_mask(&input_channel_layout, input_layout);
int input_channel_count = input_channel_layout.nb_channels;
av_opt_set_chlayout(swr, "in_chlayout", &input_channel_layout, 0);
av_channel_layout_uninit(&input_channel_layout);
AVChannelLayout output_channel_layout;
if (config.mixdown_enable != 0) {
if (config.mixdown_channel_layout == 0) {
av_channel_layout_default(&output_channel_layout,
if (CHANNELS_FROM_ENCODED_FORMAT(output_configuration) > (unsigned) input_channel_count) {
av_channel_layout_from_mask(&output_channel_layout, input_layout);
} else {
av_channel_layout_default(&output_channel_layout,
CHANNELS_FROM_ENCODED_FORMAT(output_configuration));
}
} else {
av_channel_layout_from_mask(&output_channel_layout, config.mixdown_channel_layout);
}
} else {
av_channel_layout_from_mask(&output_channel_layout, output_layout);
}
char layout_desc[2048];
av_channel_layout_describe(&output_channel_layout, layout_desc, sizeof(layout_desc));
debug(1,"output channel layout: \"%s\"", layout_desc);
av_opt_set_chlayout(swr, "out_chlayout", &output_channel_layout, 0);
av_channel_layout_uninit(&output_channel_layout);
}
@@ -681,8 +700,10 @@ int setup_software_resampler(rtsp_conn_info *conn, ssrc_t ssrc) {
av_opt_set_int(swr, "in_channel_layout", input_layout, 0);
if (config.mixdown_enable != 0) {
if (config.mixdown_channel_layout == 0) {
output_layout =
av_get_default_channel_layout(CHANNELS_FROM_ENCODED_FORMAT(output_configuration));
if (CHANNELS_FROM_ENCODED_FORMAT(output_configuration) < av_get_channel_layout_nb_channels(input_layout)) {
output_layout =
av_get_default_channel_layout(CHANNELS_FROM_ENCODED_FORMAT(output_configuration));
} // else leave output_layout as it was: the sames as the input_layout.
} else {
output_layout = config.mixdown_channel_layout;
}
@@ -962,7 +983,7 @@ int setup_software_resampler(rtsp_conn_info *conn, ssrc_t ssrc) {
if (output_configuration_changed != 0) {
char channel_mapping_list[256] = "";
for (c = 0; c < 8; c++) {
for (c = 0; c < SPS_GREATEST_CHANNEL_COUNT; c++) {
if ((output_channels[c].allocated != 0) &&
(conn->output_channel_to_resampler_channel_map[c] != silent_channel_index)) {
char channel_mapping[32] = "";