No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | gvc/gvc-channel-map.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008 William Jon McCann
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20
21 #include "config.h"
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <unistd.h>
26
27 #include <glib.h>
28 #include <glib/gi18n-lib.h>
29
30 #include <pulse/pulseaudio.h>
31
32 #include "gvc-channel-map.h"
33 #include "gvc-channel-map-private.h"
34
35 #define GVC_CHANNEL_MAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapPrivate))
36
37 struct GvcChannelMapPrivate
38 {
39 pa_channel_map pa_map;
40 gboolean pa_volume_is_set;
41 pa_cvolume pa_volume;
42 gdouble extern_volume[NUM_TYPES]; /* volume, balance, fade, lfe */
43 gboolean can_balance;
44 gboolean can_fade;
45 };
46
47 enum {
48 VOLUME_CHANGED,
49 LAST_SIGNAL
50 };
51
52 static guint signals [LAST_SIGNAL] = { 0, };
53
54 static void gvc_channel_map_class_init (GvcChannelMapClass *klass);
55 static void gvc_channel_map_init (GvcChannelMap *channel_map);
56 static void gvc_channel_map_finalize (GObject *object);
57
58 G_DEFINE_TYPE (GvcChannelMap, gvc_channel_map, G_TYPE_OBJECT)
59
60 guint
61 gvc_channel_map_get_num_channels (const GvcChannelMap *map)
62 {
63 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), 0);
64
65 if (!pa_channel_map_valid(&map->priv->pa_map))
66 return 0;
67
68 return map->priv->pa_map.channels;
69 }
70
71 const gdouble *
72 gvc_channel_map_get_volume (GvcChannelMap *map)
73 {
74 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
75
76 if (!pa_channel_map_valid(&map->priv->pa_map))
77 return NULL;
78
79 map->priv->extern_volume[VOLUME] = (gdouble) pa_cvolume_max (&map->priv->pa_volume);
80 if (gvc_channel_map_can_balance (map))
81 map->priv->extern_volume[BALANCE] = (gdouble) pa_cvolume_get_balance (&map->priv->pa_volume, &map->priv->pa_map);
82 else
83 map->priv->extern_volume[BALANCE] = 0;
84 if (gvc_channel_map_can_fade (map))
85 map->priv->extern_volume[FADE] = (gdouble) pa_cvolume_get_fade (&map->priv->pa_volume, &map->priv->pa_map);
86 else
87 map->priv->extern_volume[FADE] = 0;
88 if (gvc_channel_map_has_lfe (map))
89 map->priv->extern_volume[LFE] = (gdouble) pa_cvolume_get_position (&map->priv->pa_volume, &map->priv->pa_map, PA_CHANNEL_POSITION_LFE);
90 else
91 map->priv->extern_volume[LFE] = 0;
92
93 return map->priv->extern_volume;
94 }
95
96 gboolean
97 gvc_channel_map_can_balance (const GvcChannelMap *map)
98 {
99 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
100
101 return map->priv->can_balance;
102 }
103
104 gboolean
105 gvc_channel_map_can_fade (const GvcChannelMap *map)
106 {
107 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
108
109 return map->priv->can_fade;
110 }
111
112 const char *
113 gvc_channel_map_get_mapping (const GvcChannelMap *map)
114 {
115 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
116
117 if (!pa_channel_map_valid(&map->priv->pa_map))
118 return NULL;
119
120 return pa_channel_map_to_pretty_name (&map->priv->pa_map);
121 }
122
123 /**
124 * gvc_channel_map_has_position: (skip)
125 * @map:
126 * @position:
127 *
128 * Returns:
129 */
130 gboolean
131 gvc_channel_map_has_position (const GvcChannelMap *map,
132 pa_channel_position_t position)
133 {
134 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
135
136 return pa_channel_map_has_position (&(map->priv->pa_map), position);
137 }
138
139 const pa_channel_map *
140 gvc_channel_map_get_pa_channel_map (const GvcChannelMap *map)
141 {
142 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
143
144 if (!pa_channel_map_valid(&map->priv->pa_map))
145 return NULL;
146
147 return &map->priv->pa_map;
148 }
149
150 const pa_cvolume *
151 gvc_channel_map_get_cvolume (const GvcChannelMap *map)
152 {
153 g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
154
155 if (!pa_channel_map_valid(&map->priv->pa_map))
156 return NULL;
157
158 return &map->priv->pa_volume;
159 }
160
161 static void
162 gvc_channel_map_class_init (GvcChannelMapClass *klass)
163 {
164 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
165
166 gobject_class->finalize = gvc_channel_map_finalize;
167
168 signals [VOLUME_CHANGED] =
169 g_signal_new ("volume-changed",
170 G_TYPE_FROM_CLASS (klass),
171 G_SIGNAL_RUN_LAST,
172 G_STRUCT_OFFSET (GvcChannelMapClass, volume_changed),
173 NULL, NULL, NULL,
174 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
175
176 g_type_class_add_private (klass, sizeof (GvcChannelMapPrivate));
177 }
178
179 void
180 gvc_channel_map_volume_changed (GvcChannelMap *map,
181 const pa_cvolume *cv,
182 gboolean set)
183 {
184 g_return_if_fail (GVC_IS_CHANNEL_MAP (map));
185 g_return_if_fail (cv != NULL);
186 g_return_if_fail (pa_cvolume_compatible_with_channel_map(cv, &map->priv->pa_map));
187
188 if (pa_cvolume_equal(cv, &map->priv->pa_volume))
189 return;
190
191 map->priv->pa_volume = *cv;
192
193 if (map->priv->pa_volume_is_set == FALSE) {
194 map->priv->pa_volume_is_set = TRUE;
195 return;
196 }
197 g_signal_emit (map, signals[VOLUME_CHANGED], 0, set);
198 }
199
200 static void
201 gvc_channel_map_init (GvcChannelMap *map)
202 {
203 map->priv = GVC_CHANNEL_MAP_GET_PRIVATE (map);
204 map->priv->pa_volume_is_set = FALSE;
205 }
206
207 static void
208 gvc_channel_map_finalize (GObject *object)
209 {
210 GvcChannelMap *channel_map;
211
212 g_return_if_fail (object != NULL);
213 g_return_if_fail (GVC_IS_CHANNEL_MAP (object));
214
215 channel_map = GVC_CHANNEL_MAP (object);
216
217 g_return_if_fail (channel_map->priv != NULL);
218
219 G_OBJECT_CLASS (gvc_channel_map_parent_class)->finalize (object);
220 }
221
222 GvcChannelMap *
223 gvc_channel_map_new (void)
224 {
225 GObject *map;
226 map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
227 return GVC_CHANNEL_MAP (map);
228 }
229
230 static void
231 set_from_pa_map (GvcChannelMap *map,
232 const pa_channel_map *pa_map)
233 {
234 g_assert (pa_channel_map_valid(pa_map));
235
236 map->priv->can_balance = pa_channel_map_can_balance (pa_map);
237 map->priv->can_fade = pa_channel_map_can_fade (pa_map);
238
239 map->priv->pa_map = *pa_map;
240 pa_cvolume_set(&map->priv->pa_volume, pa_map->channels, PA_VOLUME_NORM);
241 }
242
243 GvcChannelMap *
244 gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *pa_map)
245 {
246 GObject *map;
247 map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
248
249 set_from_pa_map (GVC_CHANNEL_MAP (map), pa_map);
250
251 return GVC_CHANNEL_MAP (map);
252 }