]> code.delx.au - pulseaudio/blob - src/pulsecore/stream-util.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / stream-util.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2013 Intel Corporation
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "stream-util.h"
27
28 #include <pulse/def.h>
29
30 #include <pulsecore/core-format.h>
31 #include <pulsecore/macro.h>
32
33 int pa_stream_get_volume_channel_map(const pa_cvolume *volume, const pa_channel_map *original_map, const pa_format_info *format,
34 pa_channel_map *volume_map) {
35 int r;
36 pa_channel_map volume_map_local;
37
38 pa_assert(volume);
39 pa_assert(format);
40 pa_assert(volume_map);
41
42 if (original_map) {
43 if (volume->channels == original_map->channels) {
44 *volume_map = *original_map;
45 return 0;
46 }
47
48 if (volume->channels == 1) {
49 pa_channel_map_init_mono(volume_map);
50 return 0;
51 }
52
53 pa_log_info("Invalid stream parameters: the volume is incompatible with the channel map.");
54 return -PA_ERR_INVALID;
55 }
56
57 r = pa_format_info_get_channel_map(format, &volume_map_local);
58 if (r == -PA_ERR_NOENTITY) {
59 if (volume->channels == 1) {
60 pa_channel_map_init_mono(volume_map);
61 return 0;
62 }
63
64 pa_log_info("Invalid stream parameters: multi-channel volume is set, but channel map is not.");
65 return -PA_ERR_INVALID;
66 }
67
68 if (r < 0) {
69 pa_log_info("Invalid channel map.");
70 return -PA_ERR_INVALID;
71 }
72
73 if (volume->channels == volume_map_local.channels) {
74 *volume_map = volume_map_local;
75 return 0;
76 }
77
78 if (volume->channels == 1) {
79 pa_channel_map_init_mono(volume_map);
80 return 0;
81 }
82
83 pa_log_info("Invalid stream parameters: the volume is incompatible with the channel map.");
84
85 return -PA_ERR_INVALID;
86 }