cras selects the best available channel map when opening a device; the process for doing this can fail if the stream that caused the device to be opened has more channels than the best channel map, and a conversion matrix is required.
cras attempts to set the format for the device to the format of the stream, but reduces the number of channels if required:
https://chromium.googlesource.com/chromiumos/third_party/adhd/+/master/cras/src/server/cras_iodev.c#456
cras then updates the channel layout based on the new number of channels:
https://chromium.googlesource.com/chromiumos/third_party/adhd/+/master/cras/src/server/cras_iodev.c#474
For ALSA devices where a conversion matrix is needed, the attempt to create a conversion matrix checks that the channels referenced in the channel map are < the number of channels:
https://chromium.googlesource.com/chromiumos/third_party/adhd/+/master/cras/src/common/cras_audio_format.c#116
The channel layout at this point is still the layout specified by the incoming stream, and whilst the number of channels has been updated to match that provided by the device, the channel layout has not, and so it may include channels from the incoming stream that are not supported in the device.
An example:
cras stream is 8 channel, output device only supports 4 channels
1. cras_iodev finds the best channel map for 8 channel stream, returns 4 channel
2. cras_iodev updates device format to be 4 channel
3. cras attempts to find best 4 channel channel-map for the device
-- no exact-match channel map exists on the device
-- cras tries to find a conversion matrix
4. code to search for conversion matrix errors as the channel layout contains 8 channels, but the device format has been reduced to 4 channels
When reducing the number of channels to match what the device supports, we should also update the channel layout to remove any no-longer-used channels.
Comment 1 by bugdroid1@chromium.org
, May 31 2018