153a5a1b3Sopenharmony_ci/*** 253a5a1b3Sopenharmony_ci This file is part of PulseAudio. 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci Copyright 2013 Intel Corporation 553a5a1b3Sopenharmony_ci 653a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 753a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as published 853a5a1b3Sopenharmony_ci by the Free Software Foundation; either version 2.1 of the License, 953a5a1b3Sopenharmony_ci or (at your option) any later version. 1053a5a1b3Sopenharmony_ci 1153a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1253a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1353a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1453a5a1b3Sopenharmony_ci General Public License for more details. 1553a5a1b3Sopenharmony_ci 1653a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public License 1753a5a1b3Sopenharmony_ci along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 1853a5a1b3Sopenharmony_ci***/ 1953a5a1b3Sopenharmony_ci 2053a5a1b3Sopenharmony_ci#ifdef HAVE_CONFIG_H 2153a5a1b3Sopenharmony_ci#include <config.h> 2253a5a1b3Sopenharmony_ci#endif 2353a5a1b3Sopenharmony_ci 2453a5a1b3Sopenharmony_ci#include "stream-util.h" 2553a5a1b3Sopenharmony_ci 2653a5a1b3Sopenharmony_ci#include <pulse/def.h> 2753a5a1b3Sopenharmony_ci 2853a5a1b3Sopenharmony_ci#include <pulsecore/core-format.h> 2953a5a1b3Sopenharmony_ci#include <pulsecore/macro.h> 3053a5a1b3Sopenharmony_ci 3153a5a1b3Sopenharmony_ciint pa_stream_get_volume_channel_map(const pa_cvolume *volume, const pa_channel_map *original_map, const pa_format_info *format, 3253a5a1b3Sopenharmony_ci pa_channel_map *volume_map) { 3353a5a1b3Sopenharmony_ci int r; 3453a5a1b3Sopenharmony_ci pa_channel_map volume_map_local; 3553a5a1b3Sopenharmony_ci 3653a5a1b3Sopenharmony_ci pa_assert(volume); 3753a5a1b3Sopenharmony_ci pa_assert(format); 3853a5a1b3Sopenharmony_ci pa_assert(volume_map); 3953a5a1b3Sopenharmony_ci 4053a5a1b3Sopenharmony_ci if (original_map) { 4153a5a1b3Sopenharmony_ci if (volume->channels == original_map->channels) { 4253a5a1b3Sopenharmony_ci *volume_map = *original_map; 4353a5a1b3Sopenharmony_ci return 0; 4453a5a1b3Sopenharmony_ci } 4553a5a1b3Sopenharmony_ci 4653a5a1b3Sopenharmony_ci if (volume->channels == 1) { 4753a5a1b3Sopenharmony_ci pa_channel_map_init_mono(volume_map); 4853a5a1b3Sopenharmony_ci return 0; 4953a5a1b3Sopenharmony_ci } 5053a5a1b3Sopenharmony_ci 5153a5a1b3Sopenharmony_ci pa_log_info("Invalid stream parameters: the volume is incompatible with the channel map."); 5253a5a1b3Sopenharmony_ci return -PA_ERR_INVALID; 5353a5a1b3Sopenharmony_ci } 5453a5a1b3Sopenharmony_ci 5553a5a1b3Sopenharmony_ci r = pa_format_info_get_channel_map(format, &volume_map_local); 5653a5a1b3Sopenharmony_ci if (r == -PA_ERR_NOENTITY) { 5753a5a1b3Sopenharmony_ci if (volume->channels == 1) { 5853a5a1b3Sopenharmony_ci pa_channel_map_init_mono(volume_map); 5953a5a1b3Sopenharmony_ci return 0; 6053a5a1b3Sopenharmony_ci } 6153a5a1b3Sopenharmony_ci 6253a5a1b3Sopenharmony_ci pa_log_info("Invalid stream parameters: multi-channel volume is set, but channel map is not."); 6353a5a1b3Sopenharmony_ci return -PA_ERR_INVALID; 6453a5a1b3Sopenharmony_ci } 6553a5a1b3Sopenharmony_ci 6653a5a1b3Sopenharmony_ci if (r < 0) { 6753a5a1b3Sopenharmony_ci pa_log_info("Invalid channel map."); 6853a5a1b3Sopenharmony_ci return -PA_ERR_INVALID; 6953a5a1b3Sopenharmony_ci } 7053a5a1b3Sopenharmony_ci 7153a5a1b3Sopenharmony_ci if (volume->channels == volume_map_local.channels) { 7253a5a1b3Sopenharmony_ci *volume_map = volume_map_local; 7353a5a1b3Sopenharmony_ci return 0; 7453a5a1b3Sopenharmony_ci } 7553a5a1b3Sopenharmony_ci 7653a5a1b3Sopenharmony_ci if (volume->channels == 1) { 7753a5a1b3Sopenharmony_ci pa_channel_map_init_mono(volume_map); 7853a5a1b3Sopenharmony_ci return 0; 7953a5a1b3Sopenharmony_ci } 8053a5a1b3Sopenharmony_ci 8153a5a1b3Sopenharmony_ci pa_log_info("Invalid stream parameters: the volume is incompatible with the channel map."); 8253a5a1b3Sopenharmony_ci 8353a5a1b3Sopenharmony_ci return -PA_ERR_INVALID; 8453a5a1b3Sopenharmony_ci} 85